mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-07-28 17:34:11 -04:00
Avoid race condition on timer creation in `GetDataRequestHanler.handle()
`
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
bfcb37c23f
commit
4e95b6e6cb
1 changed files with 10 additions and 9 deletions
|
@ -66,6 +66,16 @@ public class GetDataRequestHandler {
|
||||||
Log.traceCall(getDataRequest + "\n\tconnection=" + connection);
|
Log.traceCall(getDataRequest + "\n\tconnection=" + connection);
|
||||||
GetDataResponse getDataResponse = new GetDataResponse(new HashSet<>(dataStorage.getMap().values()),
|
GetDataResponse getDataResponse = new GetDataResponse(new HashSet<>(dataStorage.getMap().values()),
|
||||||
getDataRequest.getNonce());
|
getDataRequest.getNonce());
|
||||||
|
|
||||||
|
if (timeoutTimer == null) { // setup before sending to avoid race conditions
|
||||||
|
timeoutTimer = UserThread.runAfter(() -> {
|
||||||
|
String errorMessage = "A timeout occurred for getDataResponse:" + getDataResponse +
|
||||||
|
" on connection:" + connection;
|
||||||
|
handleFault(errorMessage, CloseConnectionReason.SEND_MSG_TIMEOUT, connection);
|
||||||
|
},
|
||||||
|
TIME_OUT_SEC, TimeUnit.SECONDS);
|
||||||
|
}
|
||||||
|
|
||||||
SettableFuture<Connection> future = networkNode.sendMessage(connection, getDataResponse);
|
SettableFuture<Connection> future = networkNode.sendMessage(connection, getDataResponse);
|
||||||
Futures.addCallback(future, new FutureCallback<Connection>() {
|
Futures.addCallback(future, new FutureCallback<Connection>() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -84,15 +94,6 @@ public class GetDataRequestHandler {
|
||||||
handleFault(errorMessage, CloseConnectionReason.SEND_MSG_FAILURE, connection);
|
handleFault(errorMessage, CloseConnectionReason.SEND_MSG_FAILURE, connection);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (timeoutTimer == null) {
|
|
||||||
timeoutTimer = UserThread.runAfter(() -> {
|
|
||||||
String errorMessage = "A timeout occurred for getDataResponse:" + getDataResponse +
|
|
||||||
" on connection:" + connection;
|
|
||||||
handleFault(errorMessage, CloseConnectionReason.SEND_MSG_TIMEOUT, connection);
|
|
||||||
},
|
|
||||||
TIME_OUT_SEC, TimeUnit.SECONDS);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue