[erlang-bugs] gen_server documentation error

Erik Søe Sørensen ess@REDACTED
Tue Jun 28 17:39:04 CEST 2011


Ah, ok - that makes sense for stop messages. You're right; that's also a 
nice property.

Adam Lindberg wrote:
> There might be code which relies on the current behavior (such as 
> cleaning up state in terminate, and expecting that that state is cleaned 
> up after the call returns).
>
> Cheers,
> Adam
>
>
>
> Erik Søe Sørensen wrote:
>   
>> I think it would appeal more to intuition if the code is fixed rather
>> than the documentation... i.e. swap the two actions.
>> That would keep all replies before the terminate action.
>>
>> Adam Lindberg wrote:
>>     
>>> Hi,
>>>
>>> In the documentation for Module:handle_call/3 in the gen_server
>>> module, it states:
>>>
>>>       
>>>> If the function returns {stop,Reason,Reply,NewState}, Reply will be
>>>> given back to From. If the function returns {stop,Reason,NewState},
>>>> any reply to From must be given explicitly using gen_server:reply/2.
>>>> The gen_server will then call Module:terminate(Reason,NewState) and
>>>> terminate.
>>>>         
>>> This is false.
>>>
>>> The true behavior exists on line 573:
>>>
>>> {stop, Reason, Reply, NState} ->
>>> {'EXIT', R} =
>>> (catch terminate(Reason, Name, Msg, Mod, NState, [])),
>>> reply(From, Reply),
>>> exit(R);
>>>
>>> The documentation should probably read:
>>>
>>> If the function returns {stop,Reason,Reply,NewState}, the gen_server
>>> will call Module:terminate(Reason,NewState) and Reply will be given
>>> back to From after the call to Module:terminate/2 has completed. If
>>> the function returns {stop,Reason,NewState}, any reply to From must be
>>> given explicitly using gen_server:reply/2.
>>>
>>> Cheers,
>>> Adam
>>>       
>> _______________________________________________
>> erlang-bugs mailing list
>> erlang-bugs@REDACTED
>> http://erlang.org/mailman/listinfo/erlang-bugs
>>     




More information about the erlang-bugs mailing list