erlangerlang-supervisor

Warning: undefined callback function terminate/3 (behaviour 'gen_statem')**


How serious is this warning? Can I use this module with this warning? What the side-effects of this warning.

Warning: undefined callback function terminate/3 (behaviour 'gen_statem')**

Erlang/OTP: 19.0.7

 
git clone https://github.com/inaka/apns4erl.git
cd apns4erl/
wget https://s3.amazonaws.com/rebar3/rebar3 && chmod +x rebar3
./rebar3 compile
===> Fetching coveralls v2.2.0
===> Fetching jsx v2.10.0
===> Analyzing applications...
===> Compiling jsx
===> Compiling coveralls
===> Verifying dependencies...
===> Fetching base64url v1.0.1
===> Fetching gun v1.3.3
===> Fetching jsx v3.0.0
===> Fetching cowlib v2.7.3
===> Analyzing applications...
===> Compiling cowlib
===> Compiling base64url
===> Compiling gun
===> Compiling jsx
===> Analyzing applications...
===> Compiling apns
**src/apns_connection.erl:22: Warning: undefined callback function terminate/3 (behaviour 'gen_statem')**

Solution

  • In Erlang/OTP 19.3 and later, as a result of this change, the terminate/3 callback is optional for gen_statem. As stated in the documentation:

    This callback is optional, so callback modules need not export it. The gen_statem module provides a default implementation without cleanup.


    So let's figure out what the consequences are of not including this function in earlier versions. According to the documentation, the terminate function would be called in three different cases:

    It's certainly imaginable that none of those situations would arise for a particular gen_statem, and thus the lack of a terminate function would have no negative consequences. In the worst case, the terminate function would be called when the process was already about to exit, thus terminating the process with a different exit reason than the original one, hiding the cause of the original problem.