-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Ethereum capability work loop can be cancelled prematurely #5508
Comments
Anything which uses
I think we can create dedicated boost asio deadline timers to manage the |
In any case I'd like for Capability implemenations to stay decoupled from I guess we could create a timer in |
Yea, off of the top of my head I think we need to do something like that so that Capability implementations can continue to run on the network thread otherwise we'd need to have Capability implementations inherit from Worker which might complicate things. |
Ethereum capabilities make use of boost deadline timers to schedule their work loop via
Host::scheduleExecution
- for example:aleth/libethereum/EthereumCapability.cpp
Lines 413 to 417 in 9e5a853
...and in
EthereumCapability::doBackgroundWork
:aleth/libethereum/EthereumCapability.cpp
Lines 488 to 490 in 9e5a853
Note that Host's usage of deadline timers is susceptible to a race condition -
Host::scheduleExecution
creates a new timer, adds it to a list, and performs an async_wait on it. The host then "garbage collects" expired timers inHost::run
, and it determines if a timer is expired by checking its expiration time:aleth/libp2p/Host.cpp
Lines 687 to 692 in 9e5a853
However, note that when a timer expires, its handler is put into a queue rather than being executed immediately - this means that there's a race condition where a handler can be executed after the timer has been deleted, resulting in the handler being executed with boost error code
operation_aborted
, which will result in the handler immediately exiting without executing any of its core logic.The text was updated successfully, but these errors were encountered: