push registration fix #2

Closed
fmodf wants to merge 0 commits from fix/push-one-session-many-registrations into master
First-time contributor

Problem

Half of QA gets no iOS pushes. The apushd log (prod, 2026-10-31) shows, for those devices, only their PushKit tokens (anotherimIOSVoipprod / anotherimIOSVoipdev) and not a single push to the alert module of the same device.

The iOS app registers two push targets: the APNs alert token and the PushKit token. libtacky sends both enables in one c2s session, on purpose (push.tcl: "the server correlates them by session id").

Stock ejabberd 26.09 mod_push keeps one registration per session. A registration's id is the session's timestamp, so both rows share it, and that breaks:

  • A pending (hibernated) session, the normal state of a suspended iPhone, held up to 24h by mod_push_keepalive, is pushed through notify(State, …) → lookup_session(U, S, ID). It reaches one registration only: the one in the {U, S, ID} cache, i.e. the last enabled. When that is PushKit's, every message is dropped (apushCalls=only) and the alert token gets nothing.
  • Once that cache entry is gone (1h cache_life_time, a restart), mod_push_mnesia:lookup_session/3 matches only [Rec] | []. With two rows it fails (case_clause) and nothing is pushed at all.
  • The archive's path (mam_message → drop_online_sessions) leaves out every registration whose id is a live session's, both of them, while the session is held.
  • delete_session deletes by id: an App Server's refusal of one token, or another enable of one node, deletes both.

Which half works depends on which token was enabled last in the session, and on whether the session was held or closed: a closed session goes through the offline/archive path, which looks up all registrations and works.

mod_apush's tests never caught it: they register PushKit and the phone from different resources, i.e. different sessions.

Fix

Fixed in mod_apush, one place, for every app build already out (no client change):

  • A second apush enable in a session that already has an apush registration of another node with the same App Server is not passed to mod_push. mod_apush answers it and keeps it as a sibling of the session's registration, in Mnesia (apush_sibling, disc copies, a bag per account). The node's registrations from other sessions are deleted, as mod_push does for its own.
  • Every push mod_push sends to the session's own registration also goes to its siblings, through mod_push:notify/7. That covers every path alike: pending, archive, offline and the keepalive's wake-up. Each sibling is decided as a registration of its own: its calls, its window and its trailing push.
  • An App Server refusal other than wait drops that sibling alone.
  • A disable of a sibling's node is answered by mod_apush. mod_push would have turned push off for the whole session.
  • Enabling the session's own registration again (mute lists changed, a new launch) keeps the sibling. The next session's enables rebuild the pair in either order and drop what the previous session left. remove_user clears the account's siblings.
  • The README has a new section, "Two registrations in one session".

Known limit: mod_client_access does not list a sibling. A revoke ends the sibling's pushes together with its primary registration.

Tests

  • one_session: both tokens enabled from one session.
    • A message to the pending session goes to the alert token, a call to PushKit.
    • The same holds with mod_push's cache cleared.
    • The archive/offline path pushes exactly once each.
    • Each token enabled again: both kept.
    • PushKit disabled: the alert token stays.
    • A fresh session enabling in the other order works.
    • An unknown node and an enable with no session are left to mod_push.
    • remove_user clears the siblings.
  • one_session_window: the sibling has its own window and trailing push; refused for good it is dropped, refused with wait or taken it is kept.
  • one_session fails on master: the message is pushed nowhere, which is the prod bug.

Checked: the suite on ejabberd 26.09's own release (the arm64 .deb unpacked, eunit from OTP maint-28, build-modules.sh's steps): all 43 tests pass, mod_apush 99.8 % of 460 lines covered. make test (the docker build) was not run here.

After deploy

  • The restart ends every session. Each phone's next connect registers the pair correctly.
  • Check apushd's log: anotherimIOSprod / anotherimIOSdev pushes should appear for the devices that showed only VoIP modules.
  • Not explained by this change: apushd logging kind=message on the VoIP modules, which mod_apush should already drop for apushCalls=only. If that persists, a push_session dump from prod is needed.
## Problem Half of QA gets no iOS pushes. The apushd log (prod, 2026-10-31) shows, for those devices, only their PushKit tokens (`anotherimIOSVoipprod` / `anotherimIOSVoipdev`) and not a single push to the alert module of the same device. The iOS app registers two push targets: the APNs alert token and the PushKit token. libtacky sends both `enable`s **in one c2s session**, on purpose (push.tcl: "the server correlates them by session id"). Stock ejabberd 26.09 `mod_push` keeps **one registration per session**. A registration's id is the session's timestamp, so both rows share it, and that breaks: - **A pending (hibernated) session**, the normal state of a suspended iPhone, held up to 24h by `mod_push_keepalive`, is pushed through `notify(State, …)` → `lookup_session(U, S, ID)`. It reaches one registration only: the one in the `{U, S, ID}` cache, i.e. the last enabled. When that is PushKit's, every message is dropped (`apushCalls=only`) and the alert token gets nothing. - **Once that cache entry is gone** (1h `cache_life_time`, a restart), `mod_push_mnesia:lookup_session/3` matches only `[Rec] | []`. With two rows it fails (`case_clause`) and nothing is pushed at all. - **The archive's path** (`mam_message` → `drop_online_sessions`) leaves out every registration whose id is a live session's, both of them, while the session is held. - **`delete_session` deletes by id:** an App Server's refusal of one token, or another `enable` of one node, deletes both. Which half works depends on which token was enabled last in the session, and on whether the session was held or closed: a closed session goes through the offline/archive path, which looks up all registrations and works. `mod_apush`'s tests never caught it: they register PushKit and the phone from different resources, i.e. different sessions. ## Fix Fixed in `mod_apush`, one place, for every app build already out (no client change): - A second apush `enable` in a session that already has an apush registration of another node with the same App Server is **not passed to `mod_push`**. `mod_apush` answers it and keeps it as a *sibling* of the session's registration, in Mnesia (`apush_sibling`, disc copies, a bag per account). The node's registrations from other sessions are deleted, as `mod_push` does for its own. - Every push `mod_push` sends to the session's own registration also goes to its siblings, through `mod_push:notify/7`. That covers every path alike: pending, archive, offline and the keepalive's wake-up. Each sibling is decided as a registration of its own: its calls, its window and its trailing push. - An App Server refusal other than `wait` drops that sibling alone. - A `disable` of a sibling's node is answered by `mod_apush`. `mod_push` would have turned push off for the whole session. - Enabling the session's own registration again (mute lists changed, a new launch) keeps the sibling. The next session's enables rebuild the pair in either order and drop what the previous session left. `remove_user` clears the account's siblings. - The README has a new section, "Two registrations in one session". Known limit: `mod_client_access` does not list a sibling. A revoke ends the sibling's pushes together with its primary registration. ## Tests - `one_session`: both tokens enabled from one session. - A message to the pending session goes to the alert token, a call to PushKit. - The same holds with `mod_push`'s cache cleared. - The archive/offline path pushes exactly once each. - Each token enabled again: both kept. - PushKit disabled: the alert token stays. - A fresh session enabling in the other order works. - An unknown node and an enable with no session are left to `mod_push`. - `remove_user` clears the siblings. - `one_session_window`: the sibling has its own window and trailing push; refused for good it is dropped, refused with `wait` or taken it is kept. - `one_session` **fails on master**: the message is pushed nowhere, which is the prod bug. Checked: the suite on ejabberd 26.09's own release (the arm64 .deb unpacked, eunit from OTP maint-28, `build-modules.sh`'s steps): all 43 tests pass, `mod_apush` 99.8 % of 460 lines covered. `make test` (the docker build) was not run here. ## After deploy - The restart ends every session. Each phone's next connect registers the pair correctly. - Check apushd's log: `anotherimIOSprod` / `anotherimIOSdev` pushes should appear for the devices that showed only VoIP modules. - Not explained by this change: apushd logging `kind=message` on the VoIP modules, which `mod_apush` should already drop for `apushCalls=only`. If that persists, a `push_session` dump from prod is needed.
mod_apush keeps a session's second apush registration beside mod_push's one, since stock mod_push keeps one a session and the iOS app registers two in one session (libtacky enables a device's alert and PushKit tokens together): both stored under the session's id, a pending session was pushed through the one the cache held, the last enabled (PushKit's, so no message reached the phone), and once the cache entry was gone (an hour, a restart) mod_push_mnesia:lookup_session/3 met two rows it does not match and pushed nothing; the archive's path leaves the session's registrations out while it is held (mod_push_keepalive, 24h), and an App Server's refusal or another enable of one node deleted both by the id (prod 2026-10-31: half of QA without pushes, apushd's log with no alert push for the devices whose PushKit tokens it saw; the user, 2026-10-31: "давай первый вариант, начни с теста, делай в отдельной ветке"). An apush enable in a session that has an apush registration of another node with the same App Server is now kept in Mnesia (apush_sibling, disc copies, a bag per account) and answered by mod_apush, never reaching mod_push, the node's registrations of other sessions deleted as mod_push deletes them; every push mod_push sends to the session's own registration -- pending, archive, offline, the keepalive's wake-up -- goes to it too through mod_push:notify/7, decided as a registration of its own (its calls, its window and trailing push), and a refusal other than wait drops it alone. A disable of its node is answered here (mod_push would have turned push off for the whole session); enabling the session's own again keeps it, the next session's enables make the pair again in either order and drop what the session before left, remove_user drops the account's. mod_client_access does not list it. The README says so under "Two registrations in one session". Tests: one_session (both tokens from one session: a message to the alert's, a call to PushKit's, with mod_push's cache cleared too, through the archive's path once each, each enabled again, PushKit's disabled, a fresh session in the other order, a node not kept here and an enable with no session left to mod_push, remove_user) and one_session_window (the second's own window and trailing push, refused for good and for a while, taken); one_session fails on the code before this, the message pushed nowhere. Checked: the suite on ejabberd 26.09's release (the arm64 .deb unpacked, eunit from OTP maint-28, build-modules.sh's steps; no docker here), all 43 tests, mod_apush 99.8 % of 460 lines. make test not run. 493f9ad96a
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Owner

Reviewed and merged into master as 3a0b477, on top of fix/push-dead-session (2b532d9: the unacked check, registrations kept clean, the ack_kind crash fix), which prod's mod_apush already runs. The merge keeps your design unchanged; what the resolution adds:

  • bind_enable runs replace/4 (the same install's earlier token under another node dropped from mod_push's) and then enable_sibling/2.
  • push_send_notification keeps the is_away / is_push_service gates and mirrors to the siblings before deciding the primary.
  • enable_sibling's stale rule also drops a sibling of the same install (same apushResource and pushModule under another node), so a rotated token in one session does not leave two siblings of one module.

Known edge left as is: a primary re-enabled under a new node in the same session orphans its sibling until the next enable.

make test: all 129 tests, mod_apush 99.6 % of 562 lines. fix/push-siblings (the lookup by resource) is superseded and not merged. Prod deb: ejabberd-mod-apush_0~20261031.3a0b477 in /data/another-releases/push-2026-10-31.

Reviewed and merged into master as 3a0b477, on top of fix/push-dead-session (2b532d9: the unacked check, registrations kept clean, the ack_kind crash fix), which prod's mod_apush already runs. The merge keeps your design unchanged; what the resolution adds: - `bind_enable` runs `replace/4` (the same install's earlier token under another node dropped from mod_push's) and then `enable_sibling/2`. - `push_send_notification` keeps the `is_away` / `is_push_service` gates and mirrors to the siblings before deciding the primary. - `enable_sibling`'s stale rule also drops a sibling of the same install (same `apushResource` and `pushModule` under another node), so a rotated token in one session does not leave two siblings of one module. Known edge left as is: a primary re-enabled under a new node in the same session orphans its sibling until the next enable. `make test`: all 129 tests, mod_apush 99.6 % of 562 lines. fix/push-siblings (the lookup by resource) is superseded and not merged. Prod deb: ejabberd-mod-apush_0~20261031.3a0b477 in /data/another-releases/push-2026-10-31.
Owner

Closing: merged into master as 3a0b477 (see above).

Closing: merged into master as 3a0b477 (see above).
ann closed this pull request 2026-11-01 22:00:49 +00:00

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
another-im/anotherim-server!2
No description provided.