sendStanzaWithResponseCallback: Ensure exactly one callback is called

This commit is contained in:
Florian Schmaus 2017-01-30 21:01:56 +01:00
parent 46e8866440
commit 872b254db5
1 changed files with 6 additions and 1 deletions

View File

@ -1494,7 +1494,12 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
final StanzaListener packetListener = new StanzaListener() {
@Override
public void processStanza(Stanza packet) throws NotConnectedException, InterruptedException {
removeAsyncStanzaListener(this);
boolean removed = removeAsyncStanzaListener(this);
if (!removed) {
// We lost a race against the "no response" handling runnable. Avoid calling the callback, as the
// exception callback will be invoked (if any).
return;
}
try {
XMPPErrorException.ifHasErrorThenThrow(packet);
callback.processStanza(packet);