Skip to content

Decouple core session features from component discovery and improve MAM fetch error message - #2251

Merged
jubalh merged 8 commits into
masterfrom
fix-race
Nov 11, 2026
Merged

jubalh merged 8 commits into
masterfrom
fix-race

Conversation

@jubalh

@jubalh jubalh commented Nov 6, 2026 •

Copy link
Copy Markdown
Member

For users that got no PUBSUB feature announced and Server error: item-not-found this should improve the situation.

Decouple Account Readiness from Component Discovery:

  • Signal account readiness (OMEMO key publishing, Carbons, Bookmarks, and MAM) immediately once conn.domain and barejid
    finish discovery
  • Eliminate the race condition where OMEMO fails to publish on login due to slow, unreachable, nonexistent external disco components.
  • Modernize iq_disco_items_request_onconnect() to use generated stanza IDs and dedicated ID handlers.

Resolve Discovery Lookup Leaks Hangs:

  • Fix _disco_info_response_id_handler_onconnect() returning 1 when the features lookup is NULL, which previously leaked the handler in id_handlers and stalled account discovery indefinitely.

Align MUC MAM with XEP-0313 :

  • Use muc_supports_mam() for groupchats so that room history works even if the user's home server does not support MAM.

Guard Against Component Discovery Races:

  • Track in progroress component queries.
  • Provide feedback for early /sendfile or /join commands executed before background disco completes.

@jubalh jubalh added this to the next milestone Nov 6, 2026
@jubalh jubalh self-assigned this Nov 6, 2026
sv_ev_connection_features_received() waited for all items
returned by disco#items to finish before firing.
Which meant that session features like OMEMO, carbons, bookmarks, MAM
were blocked on external components like MUC or HTTP upload.

External components can take a long time.
On servers with slow or unreachable components, this delayed the session.

And because the bare JID disco#info was not tracked, it created a race
where OMEMO attempted to publish its bundle before PEP features were
received, failing with "no PUBSUB feature announced".

On servers with no disco items at all, discovery completion was never triggered.

Core session features only depend on the server domain and the user's
bare JID.

Now track domain and bare JID queries in account_features_requested and
trigger sv_ev_connection_features_received() as soon as both resolve.

Also modernize iq_disco_items_request_onconnect() to use an ID handler
instead of matching on hardcoded string IDs.

Ref: #2078
Signed-off-by: Michael Vetter <jubalh@iodoru.org>
When MAM history retrieval fails we printed:
"Server error: <condition>" message to the console without context.

Include the target JID and clarify that the error originated from MAM
so users can identify which chat/MUC failed.

Signed-off-by: Michael Vetter <jubalh@iodoru.org>
Include the target JID when available so the user knows which chat failed.

Signed-off-by: Michael Vetter <jubalh@iodoru.org>
MAM can be enabled per MUC and not just server wide.

Include the target JID and distinguish between regular chats and MUC
so the user knows which chat could not fetch history.

Signed-off-by: Michael Vetter <jubalh@iodoru.org>
Rename received_disco_items to feature_retrieval_completed to accurately
reflect its purpose.

Also ensure it is also reset to FALSE in iq_handlers_clear() so that
history requests are properly queued during reconnections.

Signed-off-by: Michael Vetter <jubalh@iodoru.org>
MAM support for MUCs is advertised by the MUC room itself via service
discovery, independent of the users home server. See XEP-0313.

We checked in iq_mam_request_older(), _iq_mam_request(), and `/history
verify` the result of connection_supports(XMPP_FEATURE_MAM2).

Because room JIDs are not tracked in conn.features_by_jid, this caused:
* False negatives: history was rejected with "MUC <room> does not support
  MAM" if the users home server lacked MAM, even when the MUC room
  fully advertised it.
* False positives: invalid MAM queries were sent to MUC rooms that did
  not support MAM if the users home server advertised MAM.

We need to use muc_supports_mam() for MUC windows and connection_supports() for 1:1.

Also remove the window loading indicator if iq_mam_request_older()
aborts early due to lack of support.

Signed-off-by: Michael Vetter <jubalh@iodoru.org>
When a disco#info response on connect failed to find the target in
features_by_jid, _disco_info_response_id_handler_onconnect() returned 1.

In _iq_handler(), returning a non zero value signals that the handler
should be kept in id_handlers.
Because a response for this stanza ID has already arrived and the ID
will never be reused, this leaked the handler in memory indefinitely.

Returning early without calling connection_features_received()
prevented account_features_requested from decrementing if the failed JID
was tracked, causing account discovery to hang forever.

Signed-off-by: Michael Vetter <jubalh@iodoru.org>
Decoupling account readiness from component discovery meant that user
commands could be executed while background disco for external components
(HTTP upload, MUC) was still going on.

If a user executed `/sendfile` or `/join room` without a domain immediately
after connect, connection_jid_for_feature() returned NULL resulting in:
* "XEP-0363 HTTP File Upload is not supported by the server"
* "Account MUC service property not found."

So let's track component discovery via components_requested and
discovering_components.

When a command executes while component discovery is still active, let
the user know that discovery is in progress rather than claiming lack of
server support.

Signed-off-by: Michael Vetter <jubalh@iodoru.org>
@jubalh
jubalh merged commit 9099b60 into master Nov 11, 2026
12 checks passed
@jubalh
jubalh deleted the fix-race branch November 11, 2026 13:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant