Smack 4.4.7: XMPPConnection setReplyTimeout value is not guaranteed when the stanza is sent asynchronously

The defaultPacketReplyTimeout = 5000 defined in SmackConfiguration generally do be applied to all instances when sending stanza in practical situation.

In aTalk implementation, a few reply timer values have been defined for use pending on instance; and get reset to SMACK_REPLY_TIMEOUT_DEFAULT after use. e.g.

    /**
     * Smack packet maximum reply timeout - Smack will immediately return on a reply or until a timeout
     * before issues exception. Need this to take care for some servers' response on some packages
     * e.g. disco#info (30 seconds). Also on some slow client e.g. Samsung SII takes up to 30
     * Sec to response to sasl authentication challenge on first login
     */
    public static final int SMACK_REPLY_EXTENDED_TIMEOUT_30 = 30000;  // 30 seconds

    // vCard save takes about 29 seconds on Note 8
    public static final int SMACK_REPLY_EXTENDED_TIMEOUT_40 = 40000;  // 40 seconds

    // Some server takes ~8sec to response due to disco#info request (default timer = 5seconds)
    // File transfer e.g. IBB across server can take more than 5 seconds
    public static final int SMACK_REPLY_EXTENDED_TIMEOUT_10 = 10000;  // 10 seconds

    public static final int SMACK_REPLY_OMEMO_INIT_TIMEOUT = 15000;  // 15 seconds

    /**
     * aTalk Smack packet reply default timeout - use Smack default instead of 10s (starting v2.1.8).
     * Too many FFR on ANR at smack.StanzaCollector.nextResult (StanzaCollector.java:206) when server is not responding.
     * - change the xmppConnect replyTimeout to smack default of 5 seconds under normal operation.
     */
    public static final int SMACK_REPLY_TIMEOUT_DEFAULT = SmackConfiguration.getDefaultReplyTimeout();

However it was found that when the stanza is sent asynchronously, the setReplyTimeout value is not guaranteed, and may get reset to SMACK_REPLY_TIMEOUT_DEFAULT by other aTalk stanza sending instance. In aTalk, the set value of 15s for the below async call was reset back to 5 seconds, causing response timeout.

OmemoManager.initializeAsync(callback);

May be it is good for some async stanza sending to include an optional parameter i.e. response timeout. Alternatively the async function may consider to implement as below:

    /**
     * Initialize the manager without blocking. Once the manager is successfully initialized, the finishedCallback will
     * be notified. It will also get notified, if an error occurs.
     *
     * @param finishedCallback callback that gets called once the manager is initialized.
     */
    public void initializeAsync(final OmemoManager.InitializationFinishedCallback finishedCallback) {
        long replyTimeout = mConnection.getReplyTimeout();
        Async.go(new Runnable() {
            @Override
            public void run() {
                try {
                    mConnection.setReplyTimeout(replyTimeout);
                    initialize();
                    finishedCallback.initializationFinished(OmemoManager.this);
                } catch (Exception e) {
                    finishedCallback.initializationFailed(e);
                }
            }
        });
    }
// ========== aTalk OmemoService implementation  ============== 

    /**
     * The method should only be called upon user authentication.
     * Init smack reply timeout for omemo preKey publish whose reply takes 7(normal) to 11s(bosh)
     * on Note10 with remote server; but takes only 2s on aTalk server.
     */
    public void initOmemoDevice()
    {
        isOmemoInitSuccessful = false;
        mConnection.setReplyTimeout(ProtocolProviderServiceJabberImpl.SMACK_REPLY_OMEMO_INIT_TIMEOUT);
        mOmemoManager.initializeAsync(this);
    }

    @Override
    public void initializationFinished(OmemoManager manager)
    {
        isOmemoInitSuccessful = true;
        mConnection.setReplyTimeout(ProtocolProviderServiceJabberImpl.SMACK_REPLY_TIMEOUT_DEFAULT);
        Timber.d("Initialize OmemoManager successful for %s", manager.getOwnDevice());
    }

    @Override
    public void initializationFailed(Exception cause)
    {
        isOmemoInitSuccessful = false;
        mConnection.setReplyTimeout(ProtocolProviderServiceJabberImpl.SMACK_REPLY_TIMEOUT_DEFAULT);

        String title = aTalkApp.getResString(R.string.omemo_init_failed_title);
        String errMsg = cause.getMessage();
        Timber.w("%s: %s", title, errMsg);
        if (errMsg != null) {
            if (errMsg.contains("Invalid IdentityKeyPairs") || errMsg.contains("CorruptedOmemoKeyException")) {
                String msg = aTalkApp.getResString(R.string.omemo_init_failed_CorruptedOmemoKeyException,
                        mOmemoManager.getOwnDevice(), errMsg);
                DialogActivity.showDialog(aTalkApp.getInstance(), title, msg);
            }
            else {
                aTalkApp.showToastMessage(R.string.omemo_init_failed_noresponse, mOmemoManager.getOwnDevice());
            }
        }
    }


// ========== aTalk logcat ============== 

06:03:49.168  D  SENT (0): 
                 <iq id='5PIP4-19' type='set'>
                   <pubsub xmlns='http://jabber.org/protocol/pubsub'>
                     <publish node='eu.siacs.conversations.axolotl.bundles:1623425521'>
                       <item>
                         <bundle xmlns='eu.siacs.conversations.axolotl'>
                           <signedPreKeyPublic signedPreKeyId='1'>
                             BV0BEyZYewkRttLx4mskQnRVfO0bpIydOWkvzFwB+d0R
                           </signedPreKeyPublic>
....
                             <preKeyPublic preKeyId='100'>
                               BRKHaTpHDt/Z3XSI/u3wjLsxqdnamEza1/ouAbWqwdQO
                             </preKeyPublic>
                           </prekeys>
                         </bundle>
                       </item>
                     </publish>
                   </pubsub>
                 </iq>
                 
                 	                
06:03:54.150  W  Long monitor contention with owner Thread-19 (17827) at void org.jivesoftware.smackx.omemo.OmemoManager.initialize()(OmemoManager.java:243) waiters=0 in org.jivesoftware.smackx.omemo.internal.OmemoDevice org.jivesoftware.smackx.omemo.OmemoManager.getOwnDevice() for 5.223s
06:03:54.150  W  OmemoManager init failed: No response received within reply timeout. Timeout was 5000ms (~5s). StanzaCollector has been cancelled. Waited for response using: IQReplyFilter: iqAndIdFilter (AndFilter: (OrFilter: (IQTypeFilter: type=error, IQTypeFilter: type=result), StanzaIdFilter: id=5PIP4-19)), : fromFilter (OrFilter: (FromMatchesFilter (full): null, FromMatchesFilter (ignoreResourcepart): swan@atalk.sytes.net, FromMatchesFilter (full): atalk.sytes.net)).

06:04:00.370  D  RECV (0): 
                 <iq xml:lang='en-US' to='swan@atalk.sytes.net/atalk-3k7ua8i' from='swan@atalk.sytes.net' type='result' id='5PIP4-19'>
                   <pubsub xmlns='http://jabber.org/protocol/pubsub'>
                     <publish node='eu.siacs.conversations.axolotl.bundles:1623425521'>
                       <item id='6AC71ED2247AE'/>
                     </publish>
                   </pubsub>
                 </iq>

Se some weird behaviour while using OmemoManager.initializeAsync() that happened on my Samsung Note10+ during testing; the observed problem is shown in the attached aTalk logcat.

For unknown reason, suddenly smack OmemoManager starts sending <pubsub xmlns=‘http://jabber.org/protocol/pubsub’> in an endless loop; Have to force aTalk to abort to stop it.

Seem like the <pubsub/> NoResponseException, coupled with other parts of aTalk Omemo activites trigger this endless loop. Manage to repeat the problem a few times, and it occurs whenever the NoResponseException happen.

Changes aTalk source to use OmemoManager.initialize(), seems to have fixed the problem.
So aTalk has dropped the use of OmemoManager.initializeAsync() as this cannot guarantees the 15 seconds reply timer set for. The initializeAsync() delayed a whooping of 8 seconds from aTalk requst to actual sending the request.

06:55:44.736  D  Initialize OmemoManager started for swordfish@atalk.sytes.net:646419288

06:55:48.500  D  SENT (0): 
                 <iq id='JISV4-107' type='set'>
                   <enable xmlns='urn:xmpp:carbons:2'/>
                 </iq>


06:55:52.819  D  SENT (0): 
                 <iq id='JISV4-109' type='set'>
                   <pubsub xmlns='http://jabber.org/protocol/pubsub'>
                     <publish node='eu.siacs.conversations.axolotl.devicelist'>
                       <item>
                         <list xmlns='eu.siacs.conversations.axolotl'>
                           <device id='327058251'/>
                           <device id='646419288'/>
                         </list>
                       </item>
                     </publish>
                   </pubsub>
                 </iq>
                 <iq id='JISV4-110' type='set'>
                   <pubsub xmlns='http://jabber.org/protocol/pubsub'>
                     <publish node='eu.siacs.conversations.axolotl.devicelist'>
                       <item>
                         <list xmlns='eu.siacs.conversations.axolotl'>
                           <device id='327058251'/>
                           <device id='646419288'/>
                         </list>
                       </item>
                     </publish>
                   </pubsub>
                 </iq>


// ======= more than 60 times this stanza get send.
06:55:53.555  D  SENT (0): 
                 <iq id='JISV4-166' type='set'>
                   <pubsub xmlns='http://jabber.org/protocol/pubsub'>
                     <publish node='eu.siacs.conversations.axolotl.devicelist'>
                       <item>
                         <list xmlns='eu.siacs.conversations.axolotl'>
                           <device id='327058251'/>
                           <device id='646419288'/>
                         </list>
                       </item>
                     </publish>
                   </pubsub>
                 </iq>

06:55:53.560  W  [1989] org.jivesoftware.smackx.carbons.CarbonManager.authenticated() Cannot check for Carbon support and / or enable carbons.
                 org.jivesoftware.smack.SmackException$NoResponseException: No response received within reply timeout. Timeout was 5000ms (~5s). StanzaCollector has been cancelled. Waited for response using: IQReplyFilter: iqAndIdFilter (AndFilter: (OrFilter: (IQTypeFilter: type=error, IQTypeFilter: type=result), StanzaIdFilter: id=JISV4-107)), : fromFilter (OrFilter: (FromMatchesFilter (full): null, FromMatchesFilter (ignoreResourcepart): swordfish@atalk.sytes.net, FromMatchesFilter (full): atalk.sytes.net)).
                 	at org.jivesoftware.smack.StanzaCollector.nextResultOrThrow(StanzaCollector.java:281)
                 	at org.jivesoftware.smack.StanzaCollector.nextResultOrThrow(StanzaCollector.java:228)
                 	at org.jivesoftware.smackx.carbons.CarbonManager.setCarbonsEnabled(CarbonManager.java:341)
                 	at org.jivesoftware.smackx.carbons.CarbonManager$3.authenticated(CarbonManager.java:166)
                 	at org.jivesoftware.smack.AbstractXMPPConnection.callConnectionAuthenticatedListener(AbstractXMPPConnection.java:1706)
                 	at org.jivesoftware.smack.AbstractXMPPConnection.afterSuccessfulLogin(AbstractXMPPConnection.java:787)
                 	at org.jivesoftware.smack.tcp.XMPPTCPConnection.afterSuccessfulLogin(XMPPTCPConnection.java:372)
                 	at org.jivesoftware.smack.tcp.XMPPTCPConnection.loginInternal(XMPPTCPConnection.java:470)
                 	at org.jivesoftware.smack.AbstractXMPPConnection.login(AbstractXMPPConnection.java:637)
                 	at net.java.sip.communicator.impl.protocol.jabber.LoginByPasswordStrategy.login(LoginByPasswordStrategy.java:105)
                 	at net.java.sip.communicator.impl.protocol.jabber.ProtocolProviderServiceJabberImpl.connectAndLogin(ProtocolProviderServiceJabberImpl.java:1273)
                 	at net.java.sip.communicator.impl.protocol.jabber.ProtocolProviderServiceJabberImpl.initializeConnectAndLogin(ProtocolProviderServiceJabberImpl.java:870)
                 	at net.java.sip.communicator.impl.protocol.jabber.ProtocolProviderServiceJabberImpl.register(ProtocolProviderServiceJabberImpl.java:727)
                 	at net.java.sip.communicator.util.account.LoginManager$RegisterProvider.run(LoginManager.java:300)


06:55:57.892  W  [2058] org.jivesoftware.smackx.omemo.OmemoManager.run() Could not publish our deviceList upon an received update.
                 org.jivesoftware.smack.SmackException$NoResponseException: No response received within reply timeout. Timeout was 5000ms (~5s). StanzaCollector has been cancelled. Waited for response using: IQReplyFilter: iqAndIdFilter (AndFilter: (OrFilter: (IQTypeFilter: type=error, IQTypeFilter: type=result), StanzaIdFilter: id=JISV4-109)), : fromFilter (OrFilter: (FromMatchesFilter (full): null, FromMatchesFilter (ignoreResourcepart): swordfish@atalk.sytes.net, FromMatchesFilter (full): atalk.sytes.net)).
                 	at org.jivesoftware.smack.StanzaCollector.nextResultOrThrow(StanzaCollector.java:281)
                 	at org.jivesoftware.smack.StanzaCollector.nextResultOrThrow(StanzaCollector.java:228)
                 	at org.jivesoftware.smackx.pubsub.LeafNode.publish(LeafNode.java:330)
                 	at org.jivesoftware.smackx.pubsub.LeafNode.publish(LeafNode.java:309)
                 	at org.jivesoftware.smackx.pubsub.PubSubManager.tryToPublishAndPossibleAutoCreate(PubSubManager.java:462)
                 	at org.jivesoftware.smackx.pep.PepManager.publish(PepManager.java:292)
                 	at org.jivesoftware.smackx.omemo.OmemoService.publishDeviceList(OmemoService.java:651)
                 	at org.jivesoftware.smackx.omemo.OmemoManager$5.run(OmemoManager.java:1030)
                 	at java.lang.Thread.run(Thread.java:920)
06:55:57.931  W  [2059] org.jivesoftware.smackx.omemo.OmemoManager.run() Could not publish our deviceList upon an received update.
                 org.jivesoftware.smack.SmackException$NoResponseException: No response received within reply timeout. Timeout was 5000ms (~5s). StanzaCollector has been cancelled. Waited for response using: IQReplyFilter: iqAndIdFilter (AndFilter: (OrFilter: (IQTypeFilter: type=error, IQTypeFilter: type=result), StanzaIdFilter: id=JISV4-110)), : fromFilter (OrFilter: (FromMatchesFilter (full): null, FromMatchesFilter (ignoreResourcepart): swordfish@atalk.sytes.net, FromMatchesFilter (full): atalk.sytes.net)).
                 	at org.jivesoftware.smack.StanzaCollector.nextResultOrThrow(StanzaCollector.java:281)
                 	at org.jivesoftware.smack.StanzaCollector.nextResultOrThrow(StanzaCollector.java:228)
                 	at org.jivesoftware.smackx.pubsub.LeafNode.publish(LeafNode.java:330)
                 	at org.jivesoftware.smackx.pubsub.LeafNode.publish(LeafNode.java:309)
                 	at org.jivesoftware.smackx.pubsub.PubSubManager.tryToPublishAndPossibleAutoCreate(PubSubManager.java:462)
                 	at org.jivesoftware.smackx.pep.PepManager.publish(PepManager.java:292)
                 	at org.jivesoftware.smackx.omemo.OmemoService.publishDeviceList(OmemoService.java:651)
                 	at org.jivesoftware.smackx.omemo.OmemoManager$5.run(OmemoManager.java:1030)
                 	at java.lang.Thread.run(Thread.java:920)
06:55:57.979  W  [2060] org.jivesoftware.smackx.omemo.OmemoManager.run() Could not publish our deviceList upon an received update.
                 org.jivesoftware.smack.SmackException$NoResponseException: No response received within reply timeout. Timeout was 5000ms (~5s). StanzaCollector has been cancelled. Waited for response using: IQReplyFilter: iqAndIdFilter (AndFilter: (OrFilter: (IQTypeFilter: type=error, IQTypeFilter: type=result), StanzaIdFilter: id=JISV4-111)), : fromFilter (OrFilter: (FromMatchesFilter (full): null, FromMatchesFilter (ignoreResourcepart): swordfish@atalk.sytes.net, FromMatchesFilter (full): atalk.sytes.net)).
                 	at org.jivesoftware.smack.StanzaCollector.nextResultOrThrow(StanzaCollector.java:281)
                 	at org.jivesoftware.smack.StanzaCollector.nextResultOrThrow(StanzaCollector.java:228)
                 	at org.jivesoftware.smackx.pubsub.LeafNode.publish(LeafNode.java:330)
                 	at org.jivesoftware.smackx.pubsub.LeafNode.publish(LeafNode.java:309)
                 	at org.jivesoftware.smackx.pubsub.PubSubManager.tryToPublishAndPossibleAutoCreate(PubSubManager.java:462)
                 	at org.jivesoftware.smackx.pep.PepManager.publish(PepManager.java:292)
                 	at org.jivesoftware.smackx.omemo.OmemoService.publishDeviceList(OmemoService.java:651)
                 	at org.jivesoftware.smackx.omemo.OmemoManager$5.run(OmemoManager.java:1030)
                 	at java.lang.Thread.run(Thread.java:920)


// many more response timeout

06:55:58.455  W  [2096] org.jivesoftware.smackx.omemo.OmemoManager.run() Could not publish our deviceList upon an received update.
                 org.jivesoftware.smack.SmackException$NoResponseException: No response received within reply timeout. Timeout was 5000ms (~5s). StanzaCollector has been cancelled. Waited for response using: IQReplyFilter: iqAndIdFilter (AndFilter: (OrFilter: (IQTypeFilter: type=error, IQTypeFilter: type=result), StanzaIdFilter: id=JISV4-147)), : fromFilter (OrFilter: (FromMatchesFilter (full): null, FromMatchesFilter (ignoreResourcepart): swordfish@atalk.sytes.net, FromMatchesFilter (full): atalk.sytes.net)).
                 	at org.jivesoftware.smack.StanzaCollector.nextResultOrThrow(StanzaCollector.java:281)
                 	at org.jivesoftware.smack.StanzaCollector.nextResultOrThrow(StanzaCollector.java:228)
                 	at org.jivesoftware.smackx.pubsub.LeafNode.publish(LeafNode.java:330)
                 	at org.jivesoftware.smackx.pubsub.LeafNode.publish(LeafNode.java:309)
                 	at org.jivesoftware.smackx.pubsub.PubSubManager.tryToPublishAndPossibleAutoCreate(PubSubManager.java:462)
                 	at org.jivesoftware.smackx.pep.PepManager.publish(PepManager.java:292)
                 	at org.jivesoftware.smackx.omemo.OmemoService.publishDeviceList(OmemoService.java:651)
                 	at org.jivesoftware.smackx.omemo.OmemoManager$5.run(OmemoManager.java:1030)
                 	at java.lang.Thread.run(Thread.java:920)
06:55:58.460  D  RECV (0): 
                 <a h='65' xmlns='urn:xmpp:sm:3'/>
06:55:58.466  W  [2097] org.jivesoftware.smackx.omemo.OmemoManager.run() Could not publish our deviceList upon an received update.
                 org.jivesoftware.smack.SmackException$NoResponseException: No response received within reply timeout. Timeout was 5000ms (~5s). StanzaCollector has been cancelled. Waited for response using: IQReplyFilter: iqAndIdFilter (AndFilter: (OrFilter: (IQTypeFilter: type=error, IQTypeFilter: type=result), StanzaIdFilter: id=JISV4-148)), : fromFilter (OrFilter: (FromMatchesFilter (full): null, FromMatchesFilter (ignoreResourcepart): swordfish@atalk.sytes.net, FromMatchesFilter (full): atalk.sytes.net)).
                 	at org.jivesoftware.smack.StanzaCollector.nextResultOrThrow(StanzaCollector.java:281)
                 	at org.jivesoftware.smack.StanzaCollector.nextResultOrThrow(StanzaCollector.java:228)
                 	at org.jivesoftware.smackx.pubsub.LeafNode.publish(LeafNode.java:330)
                 	at org.jivesoftware.smackx.pubsub.LeafNode.publish(LeafNode.java:309)
                 	at org.jivesoftware.smackx.pubsub.PubSubManager.tryToPublishAndPossibleAutoCreate(PubSubManager.java:462)
                 	at org.jivesoftware.smackx.pep.PepManager.publish(PepManager.java:292)
                 	at org.jivesoftware.smackx.omemo.OmemoService.publishDeviceList(OmemoService.java:651)
                 	at org.jivesoftware.smackx.omemo.OmemoManager$5.run(OmemoManager.java:1030)
                 	at java.lang.Thread.run(Thread.java:920)

Look like aTalk cannot just perform the sync OmemoManager.initialize(). Doing so affects all other aTalk stanza processes, causing aTalk Roster and Presence handlers not working properly.

To overcome the problems, aTalk implements the initializeAsync() locally, so as to take care of the 15s reply timer setup.

   /**
     * The method should only be called upon user authentication.
     * Init smack reply timeout for omemo preKey publish may take 7s(normal) to 11s(bosh).
     * <p>
     * Note: Must initialize the manager without blocking; else Roster and Presence are
     * not handled properly in aTalk. Once the manager is successfully initialized,
     * the finishedCallback will be notified. It will also get notified, if an error occurs.
     */
    public void initOmemoDevice() {
        isOmemoInitSuccessful = false;
        // 20240222: Drop smack OmemoManager.initializeAsync(this); has problem with reply timer set not guarantee.
        Async.go(() -> {
            try {
                Timber.d("Initialize OmemoManager started for %s", mOmemoManager.getOwnDevice());
                mConnection.setReplyTimeout(ProtocolProviderServiceJabberImpl.SMACK_REPLY_OMEMO_INIT_TIMEOUT);
                mOmemoManager.initialize();
                initializationFinished(mOmemoManager);
            } catch (Exception cause) {
                initializationFailed(cause);
            }
        });
    }

    public void initializationFinished(OmemoManager manager) {
        isOmemoInitSuccessful = true;
        mConnection.setReplyTimeout(ProtocolProviderServiceJabberImpl.SMACK_REPLY_TIMEOUT_DEFAULT);
        Timber.d("Initialize OmemoManager successful for %s", manager.getOwnDevice());
    }

    public void initializationFailed(Exception cause) {
        isOmemoInitSuccessful = false;
        mConnection.setReplyTimeout(ProtocolProviderServiceJabberImpl.SMACK_REPLY_TIMEOUT_DEFAULT);

        String title = aTalkApp.getResString(R.string.omemo_init_failed_title);
        String errMsg = cause.getMessage();
        Timber.w("%s: %s", title, errMsg);
        if (errMsg != null) {
            if (errMsg.contains("Invalid IdentityKeyPairs") || errMsg.contains("CorruptedOmemoKeyException")) {
                String msg = aTalkApp.getResString(R.string.omemo_init_failed_CorruptedOmemoKeyException,
                        mOmemoManager.getOwnDevice(), errMsg);
                DialogActivity.showDialog(aTalkApp.getInstance(), title, msg);
            }
            else {
                aTalkApp.showToastMessage(R.string.omemo_init_failed_noresponse, mOmemoManager.getOwnDevice());
            }
        }
    }

Trying to conclude, and give a view of my observation on the above problem.
Note: I am unable to provide many of the logcat errors described below, as the problem suddenly get resolved before I can capture the error results.

During the last few days of aTalk testing, aTalk user swordfish@atalk.sytes.net on my Note-10 was in endless loop throwing the NoResponseException; the occurrence is few hundreds times 500+, until it overflow AS logcat buffer; Eventually it also cause smack to crash due to error in phrasing.

07:58:54.988  W  [2127] org.jivesoftware.smackx.omemo.OmemoManager.run() Could not publish our deviceList upon an received update.
                 org.jivesoftware.smack.SmackException$NoResponseException: No response received within reply timeout. Timeout was 5000ms (~5s). StanzaCollector has been cancelled. Waited for response using: IQReplyFilter: iqAndIdFilter (AndFilter: (OrFilter: (IQTypeFilter: type=error, IQTypeFilter: type=result), StanzaIdFilter: id=T6PQY-79)), : fromFilter (OrFilter: (FromMatchesFilter (full): null, FromMatchesFilter (ignoreResourcepart): swordfish@atalk.sytes.net, FromMatchesFilter (full): atalk.sytes.net)).
                 	at org.jivesoftware.smack.StanzaCollector.nextResultOrThrow(StanzaCollector.java:281)
                 	at org.jivesoftware.smack.StanzaCollector.nextResultOrThrow(StanzaCollector.java:228)
                 	at org.jivesoftware.smackx.pubsub.LeafNode.publish(LeafNode.java:330)
                 	at org.jivesoftware.smackx.pubsub.LeafNode.publish(LeafNode.java:309)
                 	at org.jivesoftware.smackx.pubsub.PubSubManager.tryToPublishAndPossibleAutoCreate(PubSubManager.java:462)
                 	at org.jivesoftware.smackx.pep.PepManager.publish(PepManager.java:292)
                 	at org.jivesoftware.smackx.omemo.OmemoService.publishDeviceList(OmemoService.java:651)
                 	at org.jivesoftware.smackx.omemo.OmemoManager$5.run(OmemoManager.java:1030)
                 	at java.lang.Thread.run(Thread.java:920)

The NoResponseException is being thrown from within the functions below; as the reply from the xmpp server took more than the smack default reply timer of 5s.

    @SuppressWarnings("UnnecessaryLambda")
    private final PepEventListener<OmemoDeviceListElement> pepOmemoDeviceListEventListener =
                    (from, receivedDeviceList, id, message) -> {
        // Device List <list>
        OmemoCachedDeviceList deviceList;
        try {
            getOmemoService().getOmemoStoreBackend().mergeCachedDeviceList(getOwnDevice(), from,
                            receivedDeviceList);

            if (!from.asBareJid().equals(getOwnJid())) {
                return;
            }

            deviceList = getOmemoService().cleanUpDeviceList(getOwnDevice());
        } catch (IOException e) {
            LOGGER.log(Level.SEVERE,
                            "IOException while processing OMEMO PEP device updates. Message: " + message,
                                e);
            return;
        }
        final OmemoDeviceListElement_VAxolotl newDeviceList = new OmemoDeviceListElement_VAxolotl(deviceList);

        if (!newDeviceList.copyDeviceIds().equals(receivedDeviceList.copyDeviceIds())) {
            LOGGER.log(Level.FINE, "Republish deviceList due to changes:" +
                            " Received: " + Arrays.toString(receivedDeviceList.copyDeviceIds().toArray()) +
                            " Published: " + Arrays.toString(newDeviceList.copyDeviceIds().toArray()));
            Async.go(new Runnable() {
                @Override
                public void run() {
                    try {
                        Timber.w("receivedDeviceList (newDeviceList) %s (%s)", receivedDeviceList.getDeviceIds(), newDeviceList.getDeviceIds());
                        OmemoService.publishDeviceList(connection(), newDeviceList);
                    } catch (InterruptedException | XMPPException.XMPPErrorException |
                                    SmackException.NotConnectedException | SmackException.NoResponseException | PubSubException.NotALeafNodeException e) {
                        LOGGER.log(Level.WARNING, "Could not publish our deviceList upon an received update.", e);
                    }
                }
            });
        }
    };

I modified the function, so as to understand why this function get called/executed so many times, and found that the xmpp server actually push the PepEvent with only one new device ID hence executing the publishDeviceList() i.e.

The logcat show that:

receivedDeviceList (newDeviceList) [327058251] [646419288, 327058251]

But the xmpp server publish items list are not being updated due to NoResponseException???.
It may be good idea to extend this function reply timer to 10s to minimize the problem from happening again.

Any comment?

This morning the whole problem happen again on Note-10+. Here are the attached aTalk logcat:
Note: The stanza id=‘5AKYI-31’ tooks more than 59 seconds to get the reply, possibly the stanza exchanges have been overwhelm by over few hundreds of “… Could not publish our deviceList upon an received update…”

The logcat also show smack crashes with parsing InvalidXmlException.

// =====================================

07:52:44.628  W  receivedDeviceList (newDeviceList) [327058251] ([327058251, 646419288])
07:52:44.638  D  SENT (0): 
                 <iq id='5AKYI-31' type='set'>
                   <pubsub xmlns='http://jabber.org/protocol/pubsub'>
                     <publish node='eu.siacs.conversations.axolotl.devicelist'>
                       <item>
                         <list xmlns='eu.siacs.conversations.axolotl'>
                           <device id='327058251'/>
                           <device id='646419288'/>
                         </list>
                       </item>
                     </publish>
                   </pubsub>
                 </iq>


07:52:49.644  W  [2169] org.jivesoftware.smackx.omemo.OmemoManager.run() Could not publish our deviceList upon an received update.
                 org.jivesoftware.smack.SmackException$NoResponseException: No response received within reply timeout. Timeout was 5000ms (~5s). StanzaCollector has been cancelled. Waited for response using: IQReplyFilter: iqAndIdFilter (AndFilter: (OrFilter: (IQTypeFilter: type=error, IQTypeFilter: type=result), StanzaIdFilter: id=5AKYI-31)), : fromFilter (OrFilter: (FromMatchesFilter (full): null, FromMatchesFilter (ignoreResourcepart): swordfish@atalk.sytes.net, FromMatchesFilter (full): atalk.sytes.net)).
                 	at org.jivesoftware.smack.StanzaCollector.nextResultOrThrow(StanzaCollector.java:281)
                 	at org.jivesoftware.smack.StanzaCollector.nextResultOrThrow(StanzaCollector.java:228)
                 	at org.jivesoftware.smackx.pubsub.LeafNode.publish(LeafNode.java:330)
                 	at org.jivesoftware.smackx.pubsub.LeafNode.publish(LeafNode.java:309)
                 	at org.jivesoftware.smackx.pubsub.PubSubManager.tryToPublishAndPossibleAutoCreate(PubSubManager.java:462)
                 	at org.jivesoftware.smackx.pep.PepManager.publish(PepManager.java:292)
                 	at org.jivesoftware.smackx.omemo.OmemoService.publishDeviceList(OmemoService.java:651)
                 	at org.jivesoftware.smackx.omemo.OmemoManager$5.run(OmemoManager.java:1033)
                 	at java.lang.Thread.run(Thread.java:920)
                 
07:53:43.583  D  RECV (0): 
                 <iq xml:lang='en' to='swordfish@atalk.sytes.net/atalk' from='swordfish@atalk.sytes.net' type='result' id='5AKYI-319'>
                   <pubsub xmlns='http://jabber.org/protocol/pubsub'>
                     <publish node='eu.siacs.conversations.axolotl.devicelist'>
                       <item id='6ACB2D06A5878'/>
                     </publish>
                   </pubsub>
                 </iq>
                 
               
// ============== (captured at different session)               
--------- beginning of crash
18:17:46.265  E  FATAL EXCEPTION: Smack Writer (2)
                 Process: org.atalk.android, PID: 18761
                 java.lang.AssertionError: org.jxmpp.xml.splitter.InvalidXmlException$InvalidEmptyTagException: Invalid empty tag, expected '>', but got 'l'. Parsed xml so far: <iq id<='iqSDKXQ-1574 'id ='typeSDKXQ-1580=''set type='set'><pubsub xmlns='http://jabber.org/protocol/pubsub'><publish node'='eu.siacs.conversations.axolotl.devicelist'>><pubsub xmlns='http://jabber.org/protocol/pubsub'><<item>publish <list xmlns='eu.siacs.conversations.axolotl'><device id='327058251'/><device id='646419288'/></list></item></publish></pubsub></iq>node='eu.siacs.conversations.axolotl.devicelist'<r xmlns='urn:xmpp:sm:3'/>><item><list xmlns='eu.siacs.conversations.axolotl'><device id='327058251'/><device <iq id='SDKXQ-1581' id='646419288'/>type='set'><</l
                 	at org.jivesoftware.smack.debugger.SmackDebugger.lambda$newConnectionWriter$3$org-jivesoftware-smack-debugger-SmackDebugger(SmackDebugger.java:126)
                 	at org.jivesoftware.smack.debugger.SmackDebugger$$ExternalSyntheticLambda3.write(Unknown Source:2)
                 	at org.jivesoftware.smack.util.ObservableWriter.notifyListeners(ObservableWriter.java:103)
                 	at org.jivesoftware.smack.util.ObservableWriter.maybeNotifyListeners(ObservableWriter.java:87)
                 	at org.jivesoftware.smack.util.ObservableWriter.write(ObservableWriter.java:74)
                 	at java.io.Writer.append(Writer.java:227)
                 	at org.jivesoftware.smack.util.XmlStringBuilder.lambda$write$0(XmlStringBuilder.java:675)
                 	at org.jivesoftware.smack.util.XmlStringBuilder$$ExternalSyntheticLambda1.accept(Unknown Source:4)
                 	at org.jivesoftware.smack.util.XmlStringBuilder.appendXmlTo(XmlStringBuilder.java:717)
                 	at org.jivesoftware.smack.util.XmlStringBuilder.write(XmlStringBuilder.java:673)
                 	at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketWriter.writePackets(XMPPTCPConnection.java:1356)
                 	at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketWriter.access$4200(XMPPTCPConnection.java:1172)
                 	at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketWriter$1.run(XMPPTCPConnection.java:1222)
                 	at java.lang.Thread.run(Thread.java:920)
                 Caused by: org.jxmpp.xml.splitter.InvalidXmlException$InvalidEmptyTagException: Invalid empty tag, expected '>', but got 'l'. Parsed xml so far: <iq id<='iqSDKXQ-1574 'id ='typeSDKXQ-1580=''set type='set'><pubsub xmlns='http://jabber.org/protocol/pubsub'><publish node'='eu.siacs.conversations.axolotl.devicelist'>><pubsub xmlns='http://jabber.org/protocol/pubsub'><<item>publish <list xmlns='eu.siacs.conversations.axolotl'><device id='327058251'/><device id='646419288'/></list></item></publish></pubsub></iq>node='eu.siacs.conversations.axolotl.devicelist'<r xmlns='urn:xmpp:sm:3'/>><item><list xmlns='eu.siacs.conversations.axolotl'><device id='327058251'/><device <iq id='SDKXQ-1581' id='646419288'/>type='set'><</l
                 	at org.jxmpp.xml.splitter.XmlSplitter.processChar(XmlSplitter.java:338)
                 	at org.jxmpp.xml.splitter.XmlSplitter.write(XmlSplitter.java:155)
                 	at java.io.Writer.write(Writer.java:192)
                 	at java.io.Writer.write(Writer.java:157)
                 	at java.io.Writer.append(Writer.java:227)
                 	at org.jivesoftware.smack.debugger.SmackDebugger.lambda$newConnectionWriter$3$org-jivesoftware-smack-debugger-SmackDebugger(SmackDebugger.java:123)
                 	at org.jivesoftware.smack.debugger.SmackDebugger$$ExternalSyntheticLambda3.write(Unknown Source:2) 
                 	at org.jivesoftware.smack.util.ObservableWriter.notifyListeners(ObservableWriter.java:103) 
                 	at org.jivesoftware.smack.util.ObservableWriter.maybeNotifyListeners(ObservableWriter.java:87) 
                 	at org.jivesoftware.smack.util.ObservableWriter.write(ObservableWriter.java:74) 
                 	at java.io.Writer.append(Writer.java:227) 
                 	at org.jivesoftware.smack.util.XmlStringBuilder.lambda$write$0(XmlStringBuilder.java:675) 
                 	at org.jivesoftware.smack.util.XmlStringBuilder$$ExternalSyntheticLambda1.accept(Unknown Source:4) 
                 	at org.jivesoftware.smack.util.XmlStringBuilder.appendXmlTo(XmlStringBuilder.java:717) 
                 	at org.jivesoftware.smack.util.XmlStringBuilder.write(XmlStringBuilder.java:673) 
                 	at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketWriter.writePackets(XMPPTCPConnection.java:1356) 
                 	at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketWriter.access$4200(XMPPTCPConnection.java:1172) 
                 	at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketWriter$1.run(XMPPTCPConnection.java:1222) 
                 	at java.lang.Thread.run(Thread.java:920)

Below described the process on aTalk test observation, and finally find a solution to fix both the problems.

Basically there are two major problems observed on aTalk, and need to be fixed.
1a. aTalk set smack relay timer cannot be guaranteed when the function is being executed in Async.go()
1b. aTalk is having problem with NoResponseException, and endless loop in executing

PepEventListener pepOmemoDeviceListEventListener

and eventually crashes smack with InvalidXmlException.

Finally aTalk decided to make local changes, replacing the 2 files in smack-omemo library i.e.
2a. OmemoManager.java and
2b. OmemoService.java classes

// ===== OmemoManager.java changes are shown here ==========

public static final int SMACK_REPLY_OMEMO_PUBLISH = 15000;
private Set<Integer> publishedDeviceList;

    /**
     * Initializes the OmemoManager. This method must be called before the manager can be used.
     *
     * @throws CorruptedOmemoKeyException if the OMEMO key is corrupted.
     * @throws InterruptedException if the calling thread was interrupted.
     * @throws SmackException.NoResponseException if there was no response from the remote entity.
     * @throws SmackException.NotConnectedException if the XMPP connection is not connected.
     * @throws XMPPException.XMPPErrorException if there was an XMPP error returned.
     * @throws SmackException.NotLoggedInException if the XMPP connection is not authenticated.
     * @throws PubSubException.NotALeafNodeException if a PubSub leaf node operation was attempted on a non-leaf node.
     * @throws IOException if an I/O error occurred.
     */
    public synchronized void initialize()
            throws SmackException.NotLoggedInException, CorruptedOmemoKeyException, InterruptedException,
            SmackException.NoResponseException, SmackException.NotConnectedException, XMPPException.XMPPErrorException,
            PubSubException.NotALeafNodeException, IOException {
        if (!connection().isAuthenticated()) {
            throw new SmackException.NotLoggedInException();
        }

        if (getTrustCallback() == null) {
            throw new IllegalStateException("No TrustCallback set.");
        }

        LOGGER.log(Level.INFO, "Start OmemoManager.initialize()");
        getConnection().setReplyTimeout(SMACK_REPLY_OMEMO_PUBLISH);
        getOmemoService().init(new LoggedInOmemoManager(this));
    }

    /**
     * Initialize the manager without blocking. Once the manager is successfully initialized, the finishedCallback will
     * be notified. It will also get notified, if an error occurs.
     *
     * @param finishedCallback callback that gets called once the manager is initialized.
     */
    public void initializeAsync(final InitializationFinishedCallback finishedCallback) {
        Async.go(new Runnable() {
            @Override
            public void run() {
                try {
                    initialize();
                    finishedCallback.initializationFinished(OmemoManager.this);
                } catch (Exception e) {
                    finishedCallback.initializationFailed(e);
                }
                getConnection().setReplyTimeout(SmackConfiguration.getDefaultReplyTimeout());
            }
        });
    }


    @SuppressWarnings("UnnecessaryLambda")
    private final PepEventListener<OmemoDeviceListElement> pepOmemoDeviceListEventListener =
                    (from, receivedDeviceList, id, message) -> {
        // Device List <list>
        OmemoCachedDeviceList deviceList;
        try {
            getOmemoService().getOmemoStoreBackend().mergeCachedDeviceList(getOwnDevice(), from,
                            receivedDeviceList);

            if (!from.asBareJid().equals(getOwnJid())) {
                return;
            }

            deviceList = getOmemoService().cleanUpDeviceList(getOwnDevice());
        } catch (IOException e) {
            LOGGER.log(Level.SEVERE,
                            "IOException while processing OMEMO PEP device updates. Message: " + message,
                                e);
            return;
        }
        final OmemoDeviceListElement_VAxolotl newDeviceList = new OmemoDeviceListElement_VAxolotl(deviceList);

        if (!newDeviceList.copyDeviceIds().equals(receivedDeviceList.copyDeviceIds())
                && !newDeviceList.copyDeviceIds().equals(publishedDeviceList)) {
            LOGGER.log(Level.FINE, "Republish deviceList due to changes:" +
                            " Received: " + Arrays.toString(receivedDeviceList.copyDeviceIds().toArray()) +
                            " Published: " + Arrays.toString(newDeviceList.copyDeviceIds().toArray()));
            Async.go(new Runnable() {
                @Override
                public void run() {
                    try {
                        LOGGER.log(Level.INFO, "received (new) DeviceList: " + receivedDeviceList.getDeviceIds()
                                + " (" + newDeviceList.getDeviceIds() + ")");
                        getConnection().setReplyTimeout(SMACK_REPLY_OMEMO_PUBLISH);
                        OmemoService.publishDeviceList(connection(), newDeviceList);
                        publishedDeviceList = newDeviceList.copyDeviceIds();
                    } catch (InterruptedException | XMPPException.XMPPErrorException |
                                    SmackException.NotConnectedException | SmackException.NoResponseException | PubSubException.NotALeafNodeException e) {
                        LOGGER.log(Level.WARNING, "Could not publish our deviceList upon an received update.", e);
                    }
                    getConnection().setReplyTimeout(SmackConfiguration.getDefaultReplyTimeout());
                }
            });
        }
    };

Originally, aTalk first attempt is to change only one class file i.e. OmemoManager.java.

#1b. Stop further process of pubsub#event send from server, once it was handled successfully.
This was resolved with the introduction of publishedDeviceList. From test result, xmpp server sends a total of 15 x pubsub#event, upon aTalk successfully process the event after the third event, all the subsequent events are ignored. This fixes the #1b issue.

#1a. Move the setReplyTimeout just before calling, however was found not working.

getOmemoService().init(new LoggedInOmemoManager(this));

The set value can still be reset to 5s by other aTalk stanza processes;
there is about 2.9s between setReplyTimeout() and the actually stanza data being sent.
Eventually the setReplyTimeout() has to be moved to OmemoService.java class to get it to work properly.
See below source and test results.

May be the smack team would consider to implement the same or equivalant in the smack standard library.

==== TEST RESULT ====

// =============== OmemoManager#initialize ======================            

11:25:34.588  I  [2153] org.jivesoftware.smackx.omemo.OmemoManager.initialize() Start OmemoManager.initialize()

11:25:37.399  I  [2171] org.jivesoftware.smackx.omemo.OmemoService.publishBundle() Start OmemoService.publishBundle()
11:25:37.778  D  SENT (0):
                 <iq id='G5WU2-18' type='set'>
                   <pubsub xmlns='http://jabber.org/protocol/pubsub'>
                     <publish node='eu.siacs.conversations.axolotl.bundles:646419288'>
                       <item>
                         <bundle xmlns='eu.siacs.conversations.axolotl'>
                           <signedPreKeyPublic signedPreKeyId='91'>
                             BQKKWZbgrtIegXEYQ2V+nkxk4ArSPZ0vemsuydBZ7IJM
                           </signedPreKeyPublic>
                           <signedPreKeySignature>
                             v8SmtxT3bq2f6oZYpz3tIoZ5n2Z4SsKANoOnJhPOyKr3WLZMZold3451xlwos9nuF8UUokDyz0GyYEPQBlhRhA==
                           </signedPreKeySignature>
                           <identityKey>
                             BX5UMfOGUCKZEn41j44IIPDNag53yAk58fnbP7obdehB
                           </identityKey>
.....                           
                             <preKeyPublic preKeyId='133'>
                               BX9ydZfIYpR8Cxq9BXKPyeRl402eyeoFp9Pq/p9GC0Mh
                             </preKeyPublic>
                           </prekeys>
                         </bundle>
                       </item>
                     </publish>
                   </pubsub>
                 </iq>                           
                                                     
11:25:42.642  W  OmemoManager init failed: No response received within reply timeout. Timeout was 5000ms (~5s). StanzaCollector has been cancelled. Waited for response using: IQReplyFilter: iqAndIdFilter (AndFilter: (OrFilter: (IQTypeFilter: type=error, IQTypeFilter: type=result), StanzaIdFilter: id=G5WU2-18)), : fromFilter (OrFilter: (FromMatchesFilter (full): null, FromMatchesFilter (ignoreResourcepart): swordfish@atalk.sytes.net, FromMatchesFilter (full): atalk.sytes.net)).

11:25:44.719  D  RECV (0): 
                 <iq xml:lang='en' to='swordfish@atalk.sytes.net/atalk' from='swordfish@atalk.sytes.net' type='result' id='G5WU2-18'>
                   <pubsub xmlns='http://jabber.org/protocol/pubsub'>
                     <publish node='eu.siacs.conversations.axolotl.bundles:646419288'>
                       <item id='6ACB5EB795147'/>
                     </publish>
                   </pubsub>
                 </iq>

// =============== aTalk home server send pubsub#event a total of 15x of the stanza below. The new fix limits the response to only 3.======================
11:25:36.864  D  RECV (0): 
                 <message to='swordfish@atalk.sytes.net/atalk' from='swordfish@atalk.sytes.net' type='headline'>
                   <event xmlns='http://jabber.org/protocol/pubsub#event'>
                     <items node='eu.siacs.conversations.axolotl.devicelist'>
                       <item id='6ACB5A651CD16'>
                         <list xmlns='eu.siacs.conversations.axolotl'>
                           <device id='327058251'/>
                         </list>
                       </item>
                     </items>
                   </event>
                   <addresses xmlns='http://jabber.org/protocol/address'>
                     <address jid='swordfish@atalk.sytes.net/atalk' type='replyto'/>
                   </addresses>
                 </message>
11:25:37.331  D  RECV (0): 
                 <message to='swordfish@atalk.sytes.net/atalk' from='swordfish@atalk.sytes.net' type='headline'>
                   <event xmlns='http://jabber.org/protocol/pubsub#event'>
                     <items node='eu.siacs.conversations.axolotl.devicelist'>
                       <item id='6ACB5A651CD16'>
                         <list xmlns='eu.siacs.conversations.axolotl'>
                           <device id='327058251'/>
                         </list>
                       </item>
                     </items>
                   </event>
                   <addresses xmlns='http://jabber.org/protocol/address'>
                     <address jid='swordfish@atalk.sytes.net/atalk-amb0rd' type='replyto'/>
                   </addresses>
                 </message>
11:25:37.483  D  RECV (0): 
                 <message to='swordfish@atalk.sytes.net/atalk' from='swordfish@atalk.sytes.net' type='headline'>
                   <event xmlns='http://jabber.org/protocol/pubsub#event'>
                     <items node='eu.siacs.conversations.axolotl.devicelist'>
                       <item id='6ACB5A651CD16'>
                         <list xmlns='eu.siacs.conversations.axolotl'>
                           <device id='327058251'/>
                         </list>
                       </item>
                     </items>
                   </event>
                   <addresses xmlns='http://jabber.org/protocol/address'>
                     <address jid='swordfish@atalk.sytes.net/atalk' type='replyto'/>
                   </addresses>
                 </message>
        

11:25:42.796  I  [2166] org.jivesoftware.smackx.omemo.OmemoManager.run() received (new) DeviceList: [327058251] ([327058251, 646419288])
11:25:42.818  I  [2167] org.jivesoftware.smackx.omemo.OmemoManager.run() received (new) DeviceList: [327058251] ([327058251, 646419288])
11:25:42.890  D  SENT (0): 
                 <iq id='G5WU2-23' type='set'>
                   <pubsub xmlns='http://jabber.org/protocol/pubsub'>
                     <publish node='eu.siacs.conversations.axolotl.devicelist'>
                       <item>
                         <list xmlns='eu.siacs.conversations.axolotl'>
                           <device id='327058251'/>
                           <device id='646419288'/>
                         </list>
                       </item>
                     </publish>
                   </pubsub>
                 </iq>
                 <iq id='G5WU2-24' type='set'>
                   <pubsub xmlns='http://jabber.org/protocol/pubsub'>
                     <publish node='eu.siacs.conversations.axolotl.devicelist'>
                       <item>
                         <list xmlns='eu.siacs.conversations.axolotl'>
                           <device id='327058251'/>
                           <device id='646419288'/>
                         </list>
                       </item>
                     </publish>
                   </pubsub>
                 </iq>

11:25:42.946  I  [2168] org.jivesoftware.smackx.omemo.OmemoManager.run() received (new) DeviceList: [327058251] ([327058251, 646419288])

11:25:42.964  D  SENT (0): 
                 <iq id='G5WU2-26' type='set'>
                   <pubsub xmlns='http://jabber.org/protocol/pubsub'>
                     <publish node='eu.siacs.conversations.axolotl.devicelist'>
                       <item>
                         <list xmlns='eu.siacs.conversations.axolotl'>
                           <device id='327058251'/>
                           <device id='646419288'/>
                         </list>
                       </item>
                     </publish>
                   </pubsub>
                 </iq>

11:25:46.057  D  RECV (0): 
                 <iq xml:lang='en' to='swordfish@atalk.sytes.net/atalk' from='swordfish@atalk.sytes.net' type='result' id='G5WU2-23'>
                   <pubsub xmlns='http://jabber.org/protocol/pubsub'>
                     <publish node='eu.siacs.conversations.axolotl.devicelist'>
                       <item id='6ACB5EB8F08D0'/>
                     </publish>
                   </pubsub>
                 </iq> 
11:25:46.086  D  RECV (0): 
                 <message to='swordfish@atalk.sytes.net/atalk' from='swordfish@atalk.sytes.net' type='headline'>
                   <event xmlns='http://jabber.org/protocol/pubsub#event'>
                     <items node='eu.siacs.conversations.axolotl.devicelist'>
                       <item id='6ACB5EB8F08D0'>
                         <list xmlns='eu.siacs.conversations.axolotl'>
                           <device id='327058251'/>
                           <device id='646419288'/>
                         </list>
                       </item>
                     </items>
                   </event>
                   <addresses xmlns='http://jabber.org/protocol/address'>
                     <address jid='swordfish@atalk.sytes.net/atalk' type='replyto'/>
                   </addresses>
                 </message>
11:25:46.125  D  RECV (0): 
                 <message to='swordfish@atalk.sytes.net' from='swordfish@atalk.sytes.net' type='headline'>
                   <event xmlns='http://jabber.org/protocol/pubsub#event'>
                     <items node='eu.siacs.conversations.axolotl.devicelist'>
                       <item id='6ACB5EB920AD'>
                         <list xmlns='eu.siacs.conversations.axolotl'>
                           <device id='327058251'/>
                           <device id='646419288'/>
                         </list>
                       </item>
                     </items>
                   </event>
                   <addresses xmlns='http://jabber.org/protocol/address'>
                     <address jid='swordfish@atalk.sytes.net/atalk' type='replyto'/>
                   </addresses>
                 </message>
11:25:46.148  D  RECV (0): 
                 <iq xml:lang='en' to='swordfish@atalk.sytes.net/atalk' from='swordfish@atalk.sytes.net' type='result' id='G5WU2-24'>
                   <pubsub xmlns='http://jabber.org/protocol/pubsub'>
                     <publish node='eu.siacs.conversations.axolotl.devicelist'>
                       <item id='6ACB5EB920AD'/>
                     </publish>
                   </pubsub>
                 </iq>
11:25:46.166  D  RECV (0): 
                 <message to='swordfish@atalk.sytes.net/atalk' from='swordfish@atalk.sytes.net' type='headline'>
                   <event xmlns='http://jabber.org/protocol/pubsub#event'>
                     <items node='eu.siacs.conversations.axolotl.devicelist'>
                       <item id='6ACB5EB920AD'>
                         <list xmlns='eu.siacs.conversations.axolotl'>
                           <device id='327058251'/>
                           <device id='646419288'/>
                         </list>
                       </item>
                     </items>
                   </event>
                   <addresses xmlns='http://jabber.org/protocol/address'>
                     <address jid='swordfish@atalk.sytes.net/atalk' type='replyto'/>
                   </addresses>
                 </message>                 

11:25:46.323  D  RECV (0): 
                 <iq xml:lang='en' to='swordfish@atalk.sytes.net/atalk' from='swordfish@atalk.sytes.net' type='result' id='G5WU2-26'>
                   <pubsub xmlns='http://jabber.org/protocol/pubsub'>
                     <publish node='eu.siacs.conversations.axolotl.devicelist'>
                       <item id='6ACB5EB992F0'/>
                     </publish>
                   </pubsub>
                 </iq>
11:25:46.368  D  RECV (0): 
                 <message to='swordfish@atalk.sytes.net/atalk' from='swordfish@atalk.sytes.net' type='headline'>
                   <event xmlns='http://jabber.org/protocol/pubsub#event'>
                     <items node='eu.siacs.conversations.axolotl.devicelist'>
                       <item id='6ACB5EB992F0'>
                         <list xmlns='eu.siacs.conversations.axolotl'>
                           <device id='327058251'/>
                           <device id='646419288'/>
                         </list>
                       </item>
                     </items>
                   </event>
                   <addresses xmlns='http://jabber.org/protocol/address'>
                     <address jid='swordfish@atalk.sytes.net/atalk' type='replyto'/>
                   </addresses>
                 </message> 
                 
                 
// Ignore by aTalk new fix for #4 to #15                
#4 11:25:46.418  D  RECV (0): 
                 <message to='swordfish@atalk.sytes.net' from='swordfish@atalk.sytes.net' type='headline'>
                   <event xmlns='http://jabber.org/protocol/pubsub#event'>
                     <items node='eu.siacs.conversations.axolotl.devicelist'>
                       <item id='6ACB5EB9234D0'>
                         <list xmlns='eu.siacs.conversations.axolotl'>
                           <device id='327058251'/>
                         </list>
                       </item>
                     </items>
                   </event>
                   <addresses xmlns='http://jabber.org/protocol/address'>
                     <address jid='swordfish@atalk.sytes.net/atalk-amb0rd' type='replyto'/>
                   </addresses>
                 </message>                                                   	                 

#15 11:25:46.705  D  RECV (0): 
                 <message to='swordfish@atalk.sytes.net/atalk' from='swordfish@atalk.sytes.net' type='headline'>
                   <event xmlns='http://jabber.org/protocol/pubsub#event'>
                     <items node='eu.siacs.conversations.axolotl.devicelist'>
                       <item id='6ACB5EB961D89'>
                         <list xmlns='eu.siacs.conversations.axolotl'>
                           <device id='327058251'/>
                         </list>
                       </item>
                     </items>
                   </event>
                   <addresses xmlns='http://jabber.org/protocol/address'>
                     <address jid='swordfish@atalk.sytes.net/atalk-amb0rd' type='replyto'/>
                   </addresses>
                 </message>

// =========== Move setReplyTimeout() to OmemService =================

    static void publishBundle(XMPPConnection connection, OmemoDevice userDevice, OmemoBundleElement bundle)
            throws XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException,
            SmackException.NoResponseException, NotALeafNodeException {
        PepManager pm = PepManager.getInstanceFor(connection);
        LOGGER.log(Level.INFO, "Start OmemoService.publishBundle()");
        connection.setReplyTimeout(OmemoManager.SMACK_REPLY_OMEMO_PUBLISH);
        pm.publish(userDevice.getBundleNodeName(), new PayloadItem<>(bundle));
    }
### Test #1
12:44:42.626  I  [2173] org.jivesoftware.smackx.omemo.OmemoManager.initialize() Start OmemoManager.initialize()
12:44:45.535  I  [2173] org.jivesoftware.smackx.omemo.OmemoService.publishBundle() Start OmemoService.publishBundle()

12:44:45.713  D  SENT (0): 
                 <iq id='IW8UA-20' type='set'>
                   <pubsub xmlns='http://jabber.org/protocol/pubsub'>
                     <publish node='eu.siacs.conversations.axolotl.bundles:646419288'>
                       <item>
                         <bundle xmlns='eu.siacs.conversations.axolotl'>
                           <signedPreKeyPublic signedPreKeyId='91'>
                             BQKKWZbgrtIegXEYQ2V+nkxk4ArSPZ0vemsuydBZ7IJM
                           </signedPreKeyPublic>
.....
                             <preKeyPublic preKeyId='133'>
                               BX9ydZfIYpR8Cxq9BXKPyeRl402eyeoFp9Pq/p9GC0Mh
                             </preKeyPublic>
                           </prekeys>
                         </bundle>
                       </item>
                     </publish>
                   </pubsub>
                 </iq>

12:44:54.019  D  RECV (0): 
                 <iq xml:lang='en' to='swordfish@atalk.sytes.net/atalk' from='swordfish@atalk.sytes.net' type='result' id='IW8UA-20'>
                   <pubsub xmlns='http://jabber.org/protocol/pubsub'>
                     <publish node='eu.siacs.conversations.axolotl.bundles:646419288'>
                       <item id='6ACB71455FF8'/>
                     </publish>
                   </pubsub>
                 </iq>
                 
                 
### Test #2
12:48:29.647  I  [2168] org.jivesoftware.smackx.omemo.OmemoManager.initialize() Start OmemoManager.initialize()                 
12:48:32.961  I  [2168] org.jivesoftware.smackx.omemo.OmemoService.publishBundle() Start OmemoService.publishBundle()
12:48:33.094  D  SENT (0): 
                 <iq id='DQ2X3-24' type='set'>
                   <pubsub xmlns='http://jabber.org/protocol/pubsub'>
                     <publish node='eu.siacs.conversations.axolotl.bundles:646419288'>
                       <item>
                         <bundle xmlns='eu.siacs.conversations.axolotl'>
                           <signedPreKeyPublic signedPreKeyId='91'>
                             BQKKWZbgrtIegXEYQ2V+nkxk4ArSPZ0vemsuydBZ7IJM
                           </signedPreKeyPublic>
....
                             <preKeyPublic preKeyId='133'>
                               BX9ydZfIYpR8Cxq9BXKPyeRl402eyeoFp9Pq/p9GC0Mh
                             </preKeyPublic>
                           </prekeys>
                         </bundle>
                       </item>
                     </publish>
                   </pubsub>
                 </iq>
                 
12:48:41.552  D  RECV (0): 
                 <iq xml:lang='en' to='swordfish@atalk.sytes.net/atalk' from='swordfish@atalk.sytes.net' type='result' id='DQ2X3-24'>
                   <pubsub xmlns='http://jabber.org/protocol/pubsub'>
                     <publish node='eu.siacs.conversations.axolotl.bundles:646419288'>
                       <item id='6ACB7228659F8'/>
                     </publish>
                   </pubsub>
                 </iq>

Tested under ideal conditions, using Note10+ and aTalk own xmpp server on the same WiFi network.
The following aTalk logcat indicates the stanza process that will failed 100% while using the
smack.defaultPacketReplyTimeout of 5 secodns. It is expected the indicated response time will be longer when connecting to a remote community server, or to servers that are heavily overloaded.

During testing it was found that the ejabberd xmpp server allows up to 4 minutes for the reply timeout

If the smack.defaultPacketReplyTimeout is globally set to 10 seconds, do your team foresee any
undesired problem in client smack operations.

04:53:31.796  D  SENT (0): 
                 <iq id='XERRE-10' type='set'>
                   <pubsub xmlns='http://jabber.org/protocol/pubsub'>
                     <publish node='eu.siacs.conversations.axolotl.bundles:646419288'>
                       <item>
...
                           </prekeys>
                         </bundle>
                       </item>
                     </publish>
                   </pubsub>
                 </iq>
04:53:40.045  D  RECV (0): 
                 <iq xml:lang='en' to='swordfish@atalk.sytes.net/atalk' from='swordfish@atalk.sytes.net' type='result' id='XERRE-10'>
                   <pubsub xmlns='http://jabber.org/protocol/pubsub'>
                     <publish node='eu.siacs.conversations.axolotl.bundles:646419288'>
                       <item id='6ACC5451E7CA8'/>
                     </publish>
                   </pubsub>
                 </iq>


04:53:31.821  D  SENT (0): 
                 <iq id='XERRE-13' type='set'>
                   <enable xmlns='urn:xmpp:carbons:2'/>
                 </iq>
04:53:40.054  D  RECV (0): 
                 <iq xml:lang='en' to='swordfish@atalk.sytes.net/atalk' from='swordfish@atalk.sytes.net' type='result' id='XERRE-13'/>


04:53:31.849  D  SENT (0): 
                 <iq to='jn.atalk.sytes.net' id='XERRE-14' type='get'>
                   <services xmlns='http://jabber.org/protocol/jinglenodes'>
                   </services>
                 </iq>
04:53:40.279  D  RECV (0): 
                 <iq xml:lang='en' to='swordfish@atalk.sytes.net/atalk' from='jn.atalk.sytes.net' type='error' id='XERRE-14'>
                   <services xmlns='http://jabber.org/protocol/jinglenodes'/>
                   <error type='cancel'>
                     <remote-server-not-found xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>
                     <text xml:lang='en' xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'>
                       DNS lookup failed: enoname
                     </text>
                   </error>
                 </iq>
                 

08:21:10.262  D  SENT (0): 
                 <iq to='swordfish@atalk.sytes.net' id='QWNRQ-8' type='get'>
                   <query xmlns='http://jabber.org/protocol/disco#info'>
                   </query>
                 </iq>
08:21:20.231  D  RECV (0): 
                 <iq xml:lang='en' to='swordfish@atalk.sytes.net/atalk-3iillhm' from='swordfish@atalk.sytes.net' type='result' id='QWNRQ-8'>
...                 
                     <feature var='http://jabber.org/protocol/commands'/>
                   </query>

//====== ejabberd server packet reply time =========/

// on AVD from swan to swordfish                 
06:12:03.177  D  SENT (0): 
                 <iq to='swordfish@atalk.sytes.net/atalk-1t3plqs' id='U7NMI-9' type='get'>
                   <query xmlns='http://jabber.org/protocol/disco#info'>
                   </query>
                 </iq>
06:12:33.180  E  DiscoveryManager.discoverInfo failed No response received within reply timeout. Timeout was 30000ms (~30s). StanzaCollector has been cancelled. Waited for response using: IQReplyFilter: iqAndIdFilter (AndFilter: (OrFilter: (IQTypeFilter: type=error, IQTypeFilter: type=result), StanzaIdFilter: id=U7NMI-9)), : fromFilter (OrFilter: (FromMatchesFilter (full): swordfish@atalk.sytes.net/atalk-1t3plqs)).
06:16:25.677  D  RECV (0): 
                 <iq xml:lang='en-US' to='swan@atalk.sytes.net/atalk-32jo6q2' from='swordfish@atalk.sytes.net/atalk-1t3plqs' type='error' id='U7NMI-9'>
                   <query xmlns='http://jabber.org/protocol/disco#info'/>
                   <error type='cancel'>
                     <service-unavailable xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>
                     <text xml:lang='en' xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'>
                       User session terminated
                     </text>
                   </error>
                 </iq>

Sorry for the late reply.

Setting the reply timeout here is without any effect, since you set it to the value it already has. Furthermore, even if you would pass a different value to setReplyTimeout() it would still be bad practice, as this sets the global reply timeout when it should be scoped to initialize().

We could change initialize() to take a reply timeout as argument. However, if you are on a low-end and/or high latency (mobile) connection, then why not increase the value of the global reply timeout?

That is already possible, albeit on the lower API level, via SmackFuture<IQ,​Exception> sendIqRequestAsync​(IQ request).

Note that a NoResposeException could also be caused by a listener blocking in the main loop of the connection, preventing the handling of responses.

As you are probably aware, there is no universal correct value for the reply timeout. Set it to low, and you abort to early although there would be a reply. Set it to high, then the user experience suffers as the applications waits for replies that may never come.

That said, if you have cases where a 5 second reply timeout is to low, then there is no harm in increasing it. It is up to you to decide if you want to increase it to 10, 15, or something even higher.

You post makes me think that we should revisit Smack’s default of 5 seconds. I am considering to increase it to 20 seconds.

Actually the value was changed to SMACK_REPLY_OMEMO_INIT_TIMEOUT in initOmemoDevice() before the function is called. However the sending of the actually stanza only happen after few seconds later, and it was overwritten by other parts of aTalk stanza sending.

Setting the reply timeout here is without any effect, since you set it to the value it already has.

Even the replyTimeout value is set in initializeAsync(), it too does not work as there are further delay in sending stanza downstream. Eventually aTalk has to set the replyTimout right at
OmemoManager#pepOmemoDeviceListEventListener PepEventListener(). See my early comment.

Recently, I found that setting a high value does face problem; it was reported in Android Console for aTalk as ANR (Android No Response).

In aTalk implementation, there are 2 instances, where the replyTimeout is set to 30s for DiscoveryManager.discoverInfo(entityJid). As this function is synchronously being executed, it blocks access to this function if the remote is late in reply. This causes the ANR on aTalk UI; still not sure how to overcome this problem.

Following are the two files changes made for aTalk implementation to resolve the above two problems.
OmemoManager also implements JingleEnvelopeManager for aTalk encrypted files send via Jingle File Transfer, you can ignore this.

aTalk has decided to do SmackConfiguration.setDefaultReplyTimeout(10000) for next aTalk release.
Any other stanzas send will dynamically change the values if higher values are required.

OmemoManager.patch (8.2 KB)
OmemoService.patch (10.8 KB)

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.