Skip to content

Commit

Permalink
RestApi: Fix parseBlockCompleteAfterBatchProcessing data race
Browse files Browse the repository at this point in the history
The parseBlockCompleteAfterBatchProcessing field is set on the block
parsing thread and read by Jersey's HTTP threads. By default, Jersey
handles requests synchronous on multiple threads.
  • Loading branch information
alvasw committed Jan 9, 2025
1 parent f079e26 commit 9463bf5
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions restapi/src/main/java/bisq/restapi/RestApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
import bisq.common.app.Version;
import bisq.common.config.Config;

import java.util.concurrent.atomic.AtomicBoolean;

import lombok.Getter;
import lombok.extern.slf4j.Slf4j;

Expand Down Expand Up @@ -69,7 +71,7 @@ public class RestApi extends ExecutableForAppWithP2p {
private OfferBookService offerBookService;
private PriceFeedService priceFeedService;
@Getter
private boolean parseBlockCompleteAfterBatchProcessing;
private final AtomicBoolean parseBlockCompleteAfterBatchProcessing = new AtomicBoolean();

public RestApi() {
super("Bisq Rest Api", "bisq_restapi", "bisq_restapi", Version.VERSION);
Expand Down Expand Up @@ -108,7 +110,7 @@ protected void applyInjector() {
@Override
public void onParseBlockCompleteAfterBatchProcessing(Block block) {
log.error("onParseBlockCompleteAfterBatchProcessing");
parseBlockCompleteAfterBatchProcessing = true;
parseBlockCompleteAfterBatchProcessing.set(true);
}
});
}
Expand All @@ -130,6 +132,6 @@ protected void onHiddenServicePublished() {
}

public void checkDaoReady() {
checkArgument(parseBlockCompleteAfterBatchProcessing, "DAO not ready yet");
checkArgument(parseBlockCompleteAfterBatchProcessing.get(), "DAO not ready yet");
}
}

0 comments on commit 9463bf5

Please sign in to comment.