-
Notifications
You must be signed in to change notification settings - Fork 9
Description
I've been running into timing issues causing Loop::disable()
to throw due to a watcher being invalidated during the invocation of the watcher callback. Essentially, if the watcher callback calls Loop::disable()
at the end of the callback after side-effects from the watcher callback have invoked Loop::cancel()
, an exception is being thrown. While it is possible to use an additional flag to code around this problem, it seems unnecessary.
Some example code: https://github.com/amphp/socket/blob/amp_v2/lib/Server.php#L37-L51
Putting the call to Loop::cancel()
in a defer watcher seems to solve the issue here. I tried the same in the Socket
class within the same lib here. However, this does not appear to have solved the problem, as tests still occasionally result in throws due to invalid watchers.
I propose that InvalidWatcherException
should not be thrown from disable()
with cancelled watchers, as disabling a cancelled watcher does not change the expectation that further events will not be received on the watcher. enable()
should continue throwing when a cancelled watcher is given.