hyperthunk/gen_server2 — pull request #2 by ehohenstein (2012-06-28 23:20:37+00:00)
Title: fixing a bug causing code reload to always fail

During a release upgrade, the system will send a {system, _, _} message that gen_server (and gen_server2) will respond to by calling sys:handle_system_msg(). sys:handle_system_msg() will then call gen_server2:system_code_change(). After the upgrade happens, the system will call gen_server:system_continue() with the new state value returned by gen_server2:system_code_change(). The gen_server2:system_continue() method expects the state record to be a GS2State record.

What had previously been returned by gen_server2:system_code_change() was [GS2State]. The result is that release upgrade fails with the the exception {badrecord,gs2_state}.

This change fixes upgrade by making gen_server2:system_code_change() return a GS2State record rather than [GS2State].

The error was almost certainly an oversight based on the fact that gen_server doesn't use a state record but instead passes its state around as a list. Consequently, gen_server:system_code_change() returns a list of values. When translating gen_server to gen_server2, this would have been easily overlooked.