Skip to content

Throwing from disable() with invalid watcher #90

@trowski

Description

@trowski

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions