Erlang: Chat server crashing on startup -
i got set of tests program should pass , local tests works fine server it's when try run remote tests server crashes.
the crash message following:
=error report==== 23-jul-2015::23:59:17 === error in process <0.39.0> on node 'nodes@127.0.0.1' exit value: {undef,[{genserver,start,[server, {server_st,[],[]},#fun<server.loop.2>],[]}]}
my start-up function looks following:
loop(st, {from, nick, connection_wanted}) -> case lists:keymember(nick, 2, st#server_st.users) of false -> {ok, st#server_st{users = st#server_st.users ++ [{from, nick}]}}; true -> {{user_already_connected, st}, st} end;
with record "server_st" defined as:
-record(server_st, {users = [], channels = []}).
finally genserver start&loop function is:
start(name, state, f) -> pid = spawn(fun() -> loop(state, f) end), register(name, pid), pid. loop(state, f) -> receive {request, from, ref, data} -> case catch(f(state, data)) of {'exit', reason} -> from!{exit, ref, reason}, loop(state, f); {r, newstate} -> from!{result, ref, r}, loop(newstate, f) end; {update, from, ref, newf} -> ! {ok, ref}, loop(state, newf); stop -> true end.
then genserver functions i'm not allowed change. if needed can post whole testsuite too.
edit digging bit further test cases , i'm unsure if server that's causing issue, remote connect function looks following:
loop(st, {connect, {_server, _machine}}) -> serverpid = {list_to_atom(_server), list_to_atom(_machine)}, case genserver:request(serverpid, {self(), st#cl_st.nick, connection_wanted}) of ok -> {ok, st#cl_st{connected_to = serverpid}}; _ -> {{error, user_already_connected, "a user nick " ++ st#cl_st.nick ++ "is connected to" ++ _server}, st} end;
edit 2 found specific row inside testsuite that's causing error:
-define(host, '127.0.0.1'). new_client(nick, guiname) -> clientname = test_client:find_unique_name("client_"), clientatom = list_to_atom(clientname), % row below causing error result = slave:start(?host, clientatom), assert_ok("start client node "++clientname, element(1,result)), clientnode = element(2,result), initstate = client:initial_state(nick, guiname), result2 = spawn(clientnode, genserver, start, [clientatom, initstate, fun client:loop/2]), assert("client startup "++clientname, is_pid(result2)), {nick, clientatom, clientnode}.
your function genserver:start/3
not exported or module genserver
not available @ node run code calls it.
Comments
Post a Comment