Documentation/code inconsistency for gen_server?

Samuel Tardieu sam@REDACTED
Thu Dec 14 18:41:24 CET 2000

I was browsing through gen_server.erl while waiting for the end of an
endless compilation, and noticed this fragment of code:

| handle_msg({'$gen_call', From, Msg}, Parent, Name, State, Mod, Time) ->
|     case catch apply(Mod, handle_call, [Msg, From, State]) of
| [...]
| 	  {stop, Reason, Reply, NState} ->
| 	      {'EXIT', R} =
| 		  (catch terminate(Reason, Name, Msg, Mod, NState, [])),
| 	      reply(From, Reply),
| 	      exit(R);
| [...]

Also, at another place:

| handle_common_reply(Reply, Parent, Name, Msg, Mod, State, Debug) ->
|     case Reply of
| [...]
| 	  {stop, Reason, NState} ->
| 	      terminate(Reason, Name, Msg, Mod, NState, Debug);
| [...]

The doc (at least the man page) of gen_server says, concerning terminate:

| The  termination reason cannot be changed here. The
| server will terminate due  toReason  regardless  of
| what was returned from this function.

Does it mean the code is wrong? This may impact supervised processes, as
they may exit without an error even if {stop, Reason, State} is returned,
or with an unrelated error if {stop, Reason, Reply, State} is returned.

More information about the erlang-questions mailing list