avoid race condition

This commit is contained in:
sneurlax 2024-02-14 11:51:59 -06:00
parent 98c095b568
commit e979a352fb

View file

@ -848,6 +848,9 @@ mixin ElectrumXInterface<T extends Bip39HDCurrency> on Bip39HDWallet<T> {
ElectrumxChainHeightService.timeStarted[cryptoCurrency.coin] =
subscriptionCreationTime;
// Doublecheck to avoid race condition.
if (ElectrumxChainHeightService.subscriptions[cryptoCurrency.coin] ==
null) {
// Set stream subscription.
ElectrumxChainHeightService.subscriptions[cryptoCurrency.coin] =
subscription.responseStream.asBroadcastStream().listen((event) {
@ -876,15 +879,16 @@ mixin ElectrumXInterface<T extends Bip39HDCurrency> on Bip39HDWallet<T> {
level: LogLevel.Error);
}
});
} else {
}
}
// A subscription already exists.
//
// Resume the stream subscription if it's paused.
if (ElectrumxChainHeightService
.subscriptions[cryptoCurrency.coin]!.isPaused) {
// If it's paused, resume it.
ElectrumxChainHeightService.subscriptions[cryptoCurrency.coin]!
.resume();
ElectrumxChainHeightService.subscriptions[cryptoCurrency.coin]!.resume();
}
// Causes synchronization to stall.
@ -913,7 +917,6 @@ mixin ElectrumXInterface<T extends Bip39HDCurrency> on Bip39HDWallet<T> {
// Retry/recurse.
return await _manageChainHeightSubscription();
}
}
// Check if the subscription has been running for too long.
if (ElectrumxChainHeightService.timeStarted[cryptoCurrency.coin] != null) {