wxe_server bug? (and patch)

Mazen Harake <>
Wed Oct 14 15:22:42 CEST 2009


There is a situation in the wx library that causes the wxe_server to 
crash when it receives a message with a pid which is considered by 
distributed Erlang to come from another node when in fact it isn't. This 
happens when net_kernel is started explicitly (I.e. Erlang going into 
distribution mode) and an wx_object (which was created before net_kernel 
was started) is destroyed.

Here is a simple example:
Create this module:

start() ->
  wx_object:start_link({local, ?MODULE}, ?MODULE, wx:get_env(), []).

close(_, _) ->
  wx_object:call(?MODULE, stop).
init(Wx) ->
  Mf = wxFrame:new(wx:null(),1,"",[{size,{300,300}}]),
  wxFrame:connect(Mf, close_window, [{callback, fun ?MODULE:close/2}]),
  {Mf, Mf}.
handle_call(stop, _From, Mf) ->
  {stop, normal, ok, Mf}.
terminate(normal, _) ->

Then run this in the shell:
Erlang R13B (erts-5.7.1) [smp:2:2] [rq:2] [async-threads:0]

Eshell V5.7.1  (abort with ^G)
1> c(test).
2> test:start().

This should give you a small frame, don't close it yet,
Now do this:
3> net_kernel:start([bad,shortnames]).

Now close the frame and you should see:
=ERROR REPORT==== 14-Oct-2009::13:17:08 ===
** Generic server <0.39.0> terminating
** Last message in was {'_wxe_destroy_',<3.42.0>}
** When Server state == {state,#Port<0.2605>,#Port<0.2602>,
** Reason for termination ==
** {badarg,[{erlang,is_process_alive,[<3.42.0>]},

The pid which comes from the port is not recognized as a local pid and 
thus erlang:is_process_alive/1 will exit with badarg. My question is: Is 
this a "feature" or a bug? I think this is a bug but I'm not sure what 
is expected from the wx library point of view. IMHO it shouldn't crash 
and just ignore it in this case because the wxe_server shouldn't be 
allowed to crash.

Anyway I put in a patch as well just in case this is something that 
should be fixed. The patch can be applied to both wx 0.98.1 and 0.98.3.



-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: wxe_server.patch
URL: <http://erlang.org/pipermail/erlang-patches/attachments/20091014/069e2253/attachment.ksh>

More information about the erlang-patches mailing list