Comparison

plugins/mod_bosh.lua @ 1864:b9389286eece

mod_bosh: Fix for 'invalid key to next' error when 2 clients lose connection at the same time
author Matthew Wild <mwild1@gmail.com>
date Fri, 02 Oct 2009 21:23:32 +0100
parent 1633:7812459eeed7
child 1865:388b125b784a
comparison
equal deleted inserted replaced
1863:51b1612325e6 1864:b9389286eece
243 end 243 end
244 core_process_stanza(session, stanza); 244 core_process_stanza(session, stanza);
245 end 245 end
246 end 246 end
247 247
248 local dead_sessions = {};
248 function on_timer() 249 function on_timer()
249 -- log("debug", "Checking for requests soon to timeout..."); 250 -- log("debug", "Checking for requests soon to timeout...");
250 -- Identify requests timing out within the next few seconds 251 -- Identify requests timing out within the next few seconds
251 local now = os_time() + 3; 252 local now = os_time() + 3;
252 for request in pairs(waiting_requests) do 253 for request in pairs(waiting_requests) do
259 end 260 end
260 end 261 end
261 end 262 end
262 263
263 now = now - 3; 264 now = now - 3;
265 local n_dead_sessions = 0;
264 for session, inactive_since in pairs(inactive_sessions) do 266 for session, inactive_since in pairs(inactive_sessions) do
265 if session.bosh_max_inactive then 267 if session.bosh_max_inactive then
266 if now - inactive_since > session.bosh_max_inactive then 268 if now - inactive_since > session.bosh_max_inactive then
267 (session.log or log)("debug", "BOSH client inactive too long, destroying session at %d", now); 269 (session.log or log)("debug", "BOSH client inactive too long, destroying session at %d", now);
268 sessions[session.sid] = nil; 270 sessions[session.sid] = nil;
269 inactive_sessions[session] = nil; 271 inactive_sessions[session] = nil;
270 sm_destroy_session(session, "BOSH client silent for over "..session.bosh_max_inactive.." seconds"); 272 n_dead_sessions = n_dead_sessions + 1;
273 dead_sessions[n_dead_sessions] = session;
271 end 274 end
272 else 275 else
273 inactive_sessions[session] = nil; 276 inactive_sessions[session] = nil;
274 end 277 end
275 end 278 end
279
280 for i=1,n_dead_sessions do
281 local session = dead_sessions[i];
282 dead_sessions[i] = nil;
283 sm_destroy_session(session, "BOSH client silent for over "..session.bosh_max_inactive.." seconds");
284 end
276 end 285 end
277 286
278 local ports = config.get(module.host, "core", "bosh_ports") or { 5280 }; 287 local ports = config.get(module.host, "core", "bosh_ports") or { 5280 };
279 httpserver.new_from_config(ports, "http-bind", handle_request); 288 httpserver.new_from_config(ports, "http-bind", handle_request);
280 289