Software /
code /
prosody
Comparison
plugins/mod_smacks.lua @ 12064:d2380fd5e421
mod_smacks: Preserve counter values on shutdown
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Fri, 17 Dec 2021 16:00:08 +0100 |
parent | 12063:d308f6901397 |
child | 12065:9102cbd2aec4 |
comparison
equal
deleted
inserted
replaced
12063:d308f6901397 | 12064:d2380fd5e421 |
---|---|
631 end | 631 end |
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 | |
637 module:hook_global("server-stopping", function() | |
638 -- Close smacks-enaled sessions ourselves instead of letting mod_c2s close | |
639 -- 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 -- resume the lost session after a restart. | |
642 for _, user in pairs(local_sessions) do | |
643 for _, session in pairs(user.sessions) do | |
644 if session.resumption_token then | |
645 if old_session_registry:set(session.username, session.resumption_token, { h = session.handled_stanza_count }) then | |
646 session.resumption_token = nil; | |
647 if session.conn then | |
648 session.conn:close() | |
649 session.conn = nil; | |
650 -- Now when mod_c2s gets here, it will immediately destroy the | |
651 -- session since it is unconnected. | |
652 end | |
653 end | |
654 end | |
655 end | |
656 end | |
657 end, -90); |