# HG changeset patch # User Matthew Wild # Date 1254515012 -3600 # Node ID b9389286eecee81a79ca0e9a139fc97f8d923738 # Parent 51b1612325e6143032bb1d23f7e4b04ce8df4d6e mod_bosh: Fix for 'invalid key to next' error when 2 clients lose connection at the same time diff -r 51b1612325e6 -r b9389286eece plugins/mod_bosh.lua --- a/plugins/mod_bosh.lua Fri Oct 02 21:20:53 2009 +0100 +++ b/plugins/mod_bosh.lua Fri Oct 02 21:23:32 2009 +0100 @@ -245,6 +245,7 @@ end end +local dead_sessions = {}; function on_timer() -- log("debug", "Checking for requests soon to timeout..."); -- Identify requests timing out within the next few seconds @@ -261,18 +262,26 @@ end now = now - 3; + local n_dead_sessions = 0; for session, inactive_since in pairs(inactive_sessions) do if session.bosh_max_inactive then if now - inactive_since > session.bosh_max_inactive then (session.log or log)("debug", "BOSH client inactive too long, destroying session at %d", now); sessions[session.sid] = nil; inactive_sessions[session] = nil; - sm_destroy_session(session, "BOSH client silent for over "..session.bosh_max_inactive.." seconds"); + n_dead_sessions = n_dead_sessions + 1; + dead_sessions[n_dead_sessions] = session; end else inactive_sessions[session] = nil; end end + + for i=1,n_dead_sessions do + local session = dead_sessions[i]; + dead_sessions[i] = nil; + sm_destroy_session(session, "BOSH client silent for over "..session.bosh_max_inactive.." seconds"); + end end local ports = config.get(module.host, "core", "bosh_ports") or { 5280 };