From 1b3a0e99bcb16383727d51c665f9034132f8a867 Mon Sep 17 00:00:00 2001 From: gered Date: Thu, 12 May 2016 13:08:50 -0400 Subject: [PATCH] ensure initial session timeout can actually timeout on new session the way this was being triggered would cause the session timeout to be triggered at the proper timeout interval, but due to the call to refresh-session-timeout not being done via the session agent and the use of send-off, the session timeout handler would not have any way to actually remove the session from the global sessions atom in practice this would only actually be a problem if clients were creating a session and then never performing a GET request to create a backchannel --- .../src/net/thegeez/browserchannel/server.clj | 38 ++++++++++--------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/clj-browserchannel/src/net/thegeez/browserchannel/server.clj b/clj-browserchannel/src/net/thegeez/browserchannel/server.clj index 5bc7a90..f9929fe 100644 --- a/clj-browserchannel/src/net/thegeez/browserchannel/server.clj +++ b/clj-browserchannel/src/net/thegeez/browserchannel/server.clj @@ -532,28 +532,30 @@ :heartbeat-interval (:keep-alive-interval options) :session-timeout-interval (:session-timeout-interval options) :data-threshold (:data-threshold options)} - session (-> (Session. id - details - nil ;; backchannel - (ArrayBuffer. - 0 ;; array-id, 0 is never used by the - ;; array-buffer, it is used by the - ;; first message with the session id - 0 ;; last-acknowledged-id - ;; to-acknowledge-arrays - clojure.lang.PersistentQueue/EMPTY - ;; to-flush-arrays - clojure.lang.PersistentQueue/EMPTY) - nil ;; heartbeat-timeout - nil ;; session-timeout - ) - ;; this first session-timeout is for the case - ;; when the client never connects with a backchannel - refresh-session-timeout) + session (Session. id + details + nil ;; backchannel + (ArrayBuffer. + 0 ;; array-id, 0 is never used by the + ;; array-buffer, it is used by the + ;; first message with the session id + 0 ;; last-acknowledged-id + ;; to-acknowledge-arrays + clojure.lang.PersistentQueue/EMPTY + ;; to-flush-arrays + clojure.lang.PersistentQueue/EMPTY) + nil ;; heartbeat-timeout + nil ;; session-timeout + ) session-agent (agent session)] (set-error-handler! session-agent (agent-error-handler-fn (str "session-" (:id session)))) (set-error-mode! session-agent :continue) + ;; add new session-agent to our list of active browserchannel sessions (swap! sessions assoc id session-agent) + ;; this first session-timeout is for the case + ;; when the client never connects with a backchannel + (send-off session-agent refresh-session-timeout) + ;; register application-level browserchannel session events (let [{:keys [on-open on-close on-receive]} (:events options)] (if on-close (add-listener id :close on-close)) (if on-receive (add-listener id :map on-receive))