Permalink
Browse files

fix {odd_info,session_timeout}

  • Loading branch information...
1 parent 7efc08a commit 350900fc7044c4468d2c91a338c48477de53e7c7 Isaev Ivan committed Apr 5, 2012
Showing with 11 additions and 10 deletions.
  1. +11 −10 src/sockjs_session.erl
View
@@ -89,9 +89,16 @@ reply(SessionPid, Multiple) when is_pid(SessionPid) ->
reply(SessionId, Multiple) ->
reply(spid(SessionId), Multiple).
-
%% --------------------------------------------------------------------------
+cancel_timer_safe(Timer, Atom) ->
+ case erlang:cancel_timer(Timer) of
+ false ->
+ receive Atom -> ok
+ after 0 -> ok end;
+ _ -> ok
+ end.
+
spid(SessionId) ->
case ets:lookup(?ETS, SessionId) of
[] -> throw(no_session);
@@ -109,7 +116,7 @@ mark_waiting(Pid, State = #session{response_pid = undefined,
heartbeat_delay = HeartbeatDelay})
when DisconnectTRef =/= undefined ->
link(Pid),
- _ = erlang:cancel_timer(DisconnectTRef),
+ cancel_timer_safe(DisconnectTRef, session_timeout),
TRef = erlang:send_after(HeartbeatDelay, self(), heartbeat_triggered),
State#session{response_pid = Pid,
disconnect_tref = undefined,
@@ -125,13 +132,7 @@ unmark_waiting(RPid, State = #session{response_pid = RPid,
_ = case HeartbeatTRef of
undefined -> ok;
triggered -> ok;
- _Else ->
- case erlang:cancel_timer(HeartbeatTRef) of
- false ->
- receive heartbeat_triggered -> ok
- after 0 -> ok end;
- _ -> ok
- end
+ _Else -> cancel_timer_safe(HeartbeatTRef, heartbeat_triggered)
end,
TRef = erlang:send_after(DisconnectDelay, self(), session_timeout),
State#session{response_pid = undefined,
@@ -143,7 +144,7 @@ unmark_waiting(_Pid, State = #session{response_pid = undefined,
disconnect_tref = DisconnectTRef,
disconnect_delay = DisconnectDelay})
when DisconnectTRef =/= undefined ->
- _ = erlang:cancel_timer(DisconnectTRef),
+ cancel_timer_safe(DisconnectTRef, session_timeout),
TRef = erlang:send_after(DisconnectDelay, self(), session_timeout),
State#session{disconnect_tref = TRef};

0 comments on commit 350900f

Please sign in to comment.