From c70a1921db214c710e144a81b15bb961fd5fd0d3 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Fri, 29 Sep 2017 15:43:29 +0200 Subject: [PATCH] Use Async.go() in OMEMO PEPListener to avoid a deadlock, since the PEP listener is synchronous. --- .../smackx/omemo/OmemoManager.java | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/smack-omemo/src/main/java/org/jivesoftware/smackx/omemo/OmemoManager.java b/smack-omemo/src/main/java/org/jivesoftware/smackx/omemo/OmemoManager.java index f635d2acb..dffd0c94b 100644 --- a/smack-omemo/src/main/java/org/jivesoftware/smackx/omemo/OmemoManager.java +++ b/smack-omemo/src/main/java/org/jivesoftware/smackx/omemo/OmemoManager.java @@ -814,16 +814,23 @@ public final class OmemoManager extends Manager { Set deviceListIds = omemoDeviceListElement.copyDeviceIds(); //enroll at the deviceList deviceListIds.add(ourDeviceId); - omemoDeviceListElement = new OmemoDeviceListVAxolotlElement(deviceListIds); + final OmemoDeviceListVAxolotlElement newOmemoDeviceListElement = new OmemoDeviceListVAxolotlElement(deviceListIds); - try { - OmemoService.publishDeviceIds(OmemoManager.this, omemoDeviceListElement); - } catch (SmackException | InterruptedException | XMPPException.XMPPErrorException e) { - //TODO: It might be dangerous NOT to retry publishing our deviceId - LOGGER.log(Level.SEVERE, - "Could not publish our device list after an update without our id was received: " - + e.getMessage()); - } + // PEPListener is a synchronous listener. Avoid any deadlocks by using an async task to update the device list. + Async.go(new Runnable() { + @Override + public void run() { + try { + OmemoService.publishDeviceIds(OmemoManager.this, newOmemoDeviceListElement); + } + catch (SmackException | InterruptedException | XMPPException.XMPPErrorException e) { + // TODO: It might be dangerous NOT to retry publishing our deviceId + LOGGER.log(Level.SEVERE, + "Could not publish our device list after an update without our id was received: " + + e.getMessage()); + } + } + }); } } }