plugins/mod_smacks.lua
changeset 12069 9102cbd2aec4
parent 12068 d2380fd5e421
child 12070 f07c8240a71d
equal deleted inserted replaced
12068:d2380fd5e421 12069:9102cbd2aec4
   632 end
   632 end
   633 
   633 
   634 module:hook("s2s-read-timeout", handle_read_timeout);
   634 module:hook("s2s-read-timeout", handle_read_timeout);
   635 module:hook("c2s-read-timeout", handle_read_timeout);
   635 module:hook("c2s-read-timeout", handle_read_timeout);
   636 
   636 
   637 module:hook_global("server-stopping", function()
   637 module:hook_global("server-stopping", function(event)
       
   638 	local reason = event.reason;
   638 	-- Close smacks-enaled sessions ourselves instead of letting mod_c2s close
   639 	-- Close smacks-enaled sessions ourselves instead of letting mod_c2s close
   639 	-- it, which invalidates the smacks session. This allows preserving the
   640 	-- it, which invalidates the smacks session. This allows preserving the
   640 	-- counter value, so it can be communicated to the client when it tries to
   641 	-- counter value, so it can be communicated to the client when it tries to
   641 	-- resume the lost session after a restart.
   642 	-- resume the lost session after a restart.
   642 	for _, user in pairs(local_sessions) do
   643 	for _, user in pairs(local_sessions) do
   643 		for _, session in pairs(user.sessions) do
   644 		for _, session in pairs(user.sessions) do
   644 			if session.resumption_token then
   645 			if session.resumption_token then
   645 				if old_session_registry:set(session.username, session.resumption_token, { h = session.handled_stanza_count }) then
   646 				if old_session_registry:set(session.username, session.resumption_token, { h = session.handled_stanza_count }) then
   646 					session.resumption_token = nil;
   647 					session.resumption_token = nil;
       
   648 
       
   649 					-- Deal with unacked stanzas
       
   650 					if session.outgoing_stanza_queue then
       
   651 						handle_unacked_stanzas(session);
       
   652 					end
       
   653 
   647 					if session.conn then
   654 					if session.conn then
   648 						session.conn:close()
   655 						session.conn:close()
   649 						session.conn = nil;
   656 						session.conn = nil;
   650 						-- Now when mod_c2s gets here, it will immediately destroy the
   657 						-- Now when mod_c2s gets here, it will immediately destroy the
   651 						-- session since it is unconnected.
   658 						-- session since it is unconnected.
   652 					end
   659 					end
       
   660 
       
   661 					-- And make sure nobody tries to send anything
       
   662 					session:close{ condition = "system-shutdown", text = reason };
   653 				end
   663 				end
   654 			end
   664 			end
   655 		end
   665 		end
   656 	end
   666 	end
   657 end, -90);
   667 end, -90);