[bisq-network/bisq] Make UserThread::runAfter* methods thread safe (#4122)

Steven Barclay notifications at github.com
Mon Apr 6 06:08:39 UTC 2020


The `UserThread::runAfter*` methods delegate to `UITimer::run(Later|Periodically)` in the case of the desktop application. These use the JavaFX `TimeLine` API (via `bisq.common.reactfx.FXTimer`) to schedule future events. However, this API isn't thread safe and isn't meant to be called outside the FX application thread. This causes occasional task misfires and out-of-order scheduling when `UserThread::runAfter` is called outside the user thread.

Make the `UITimer::run*` methods safe to call from any thread by checking we are in the application thread and delegating to `UserThread::execute` otherwise. This also improves consistency between the contracts of the `runAfter*` and execute methods. As the former has many call sites, this is safer than trying to track down all the non-thread-safe uses.

(The `Timer` used in the headless app already appears to be thread-safe.)

This fixes #4055, caused by out-of-order scheduling of the `execute` and `runAfter` tasks in the `WalletConfig.onSetupCompleted` anonymous class method in `bisq.core.btc.setup.WalletsSetup.initialize`.

Also prevent an exception caused by non-thread-safe calls into JavaFX during the shutdown of `OpenOfferManager`, which was uncovered by the above, by adding a missing `UserThread::execute` call.

<!-- 
- make yourself familiar with the CONTRIBUTING.md if you have not already (https://github.com/bisq-network/bisq/blob/master/CONTRIBUTING.md)
- make sure you follow our [coding style guidelines][https://github.com/bisq-network/style/issues)
- pick a descriptive title
- provide some meaningful PR description below
- create the PR
- in case you receive a "Change request" and/or a NACK, please react within 30 days. If not, we will close your PR and it can not be up for compensation.
- After addressing the change request, __please re-request a review!__ Otherwise we might miss your PR as we tend to only look at pull requests tagged with a "review required".
-->
You can view, comment on, or merge this pull request online at:

  https://github.com/bisq-network/bisq/pull/4122

-- Commit Summary --

  * Make UserThread::runAfter* methods thread safe

-- File Changes --

    M core/src/main/java/bisq/core/offer/OpenOfferManager.java (9)
    M desktop/src/main/java/bisq/desktop/common/UITimer.java (47)

-- Patch Links --

https://github.com/bisq-network/bisq/pull/4122.patch
https://github.com/bisq-network/bisq/pull/4122.diff

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/bisq-network/bisq/pull/4122
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.bisq.network/pipermail/bisq-github/attachments/20200405/93ad0a6d/attachment.html>


More information about the bisq-github mailing list