mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-08-22 05:29:33 -04:00
Avoid race condition on timer creation in `RequestDataHandler.requestData()
`
If the timer is created after sending the message and establishing callbacks, they may have already run on timer creation so it would be pointless (and issue a warning when triggered).
This commit is contained in:
parent
b59e3ff0f8
commit
c3fa4831c5
1 changed files with 15 additions and 15 deletions
|
@ -90,6 +90,21 @@ public class RequestDataHandler implements MessageListener {
|
||||||
|
|
||||||
log.info("We send a {} to peer {}. ", getDataRequest.getClass().getSimpleName(), nodeAddress);
|
log.info("We send a {} to peer {}. ", getDataRequest.getClass().getSimpleName(), nodeAddress);
|
||||||
|
|
||||||
|
if (timeoutTimer == null) { // setup before sending to avoid race conditions
|
||||||
|
timeoutTimer = UserThread.runAfter(() -> {
|
||||||
|
if (!stopped) {
|
||||||
|
String errorMessage = "A timeout occurred at sending getDataRequest:" + getDataRequest +
|
||||||
|
" on nodeAddress:" + nodeAddress;
|
||||||
|
log.info(errorMessage + " / RequestDataHandler=" + RequestDataHandler.this);
|
||||||
|
handleFault(errorMessage, nodeAddress, CloseConnectionReason.SEND_MSG_TIMEOUT);
|
||||||
|
} else {
|
||||||
|
log.trace("We have stopped already. We ignore that timeoutTimer.run call. " +
|
||||||
|
"Might be caused by an previous networkNode.sendMessage.onFailure.");
|
||||||
|
}
|
||||||
|
},
|
||||||
|
TIME_OUT_SEC);
|
||||||
|
}
|
||||||
|
|
||||||
SettableFuture<Connection> future = networkNode.sendMessage(nodeAddress, getDataRequest);
|
SettableFuture<Connection> future = networkNode.sendMessage(nodeAddress, getDataRequest);
|
||||||
Futures.addCallback(future, new FutureCallback<Connection>() {
|
Futures.addCallback(future, new FutureCallback<Connection>() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -119,21 +134,6 @@ public class RequestDataHandler implements MessageListener {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (timeoutTimer == null) {
|
|
||||||
timeoutTimer = UserThread.runAfter(() -> {
|
|
||||||
if (!stopped) {
|
|
||||||
String errorMessage = "A timeout occurred at sending getDataRequest:" + getDataRequest +
|
|
||||||
" on nodeAddress:" + nodeAddress;
|
|
||||||
log.info(errorMessage + " / RequestDataHandler=" + RequestDataHandler.this);
|
|
||||||
handleFault(errorMessage, nodeAddress, CloseConnectionReason.SEND_MSG_TIMEOUT);
|
|
||||||
} else {
|
|
||||||
log.trace("We have stopped already. We ignore that timeoutTimer.run call. " +
|
|
||||||
"Might be caused by an previous networkNode.sendMessage.onFailure.");
|
|
||||||
}
|
|
||||||
},
|
|
||||||
TIME_OUT_SEC);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
log.warn("We have stopped already. We ignore that requestData call.");
|
log.warn("We have stopped already. We ignore that requestData call.");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue