Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

HandleWatcher replacement error handling logic is broken #98

Open
@glasser

Description

@glasser

7e10102 changed HandleWatcher.start to "Remove the old one if we found two same file handles" instead of throwing an exception.

Choosing to replace an existing HandleWatcher with a new one with just a logged error instead of throwing an exception might make sense. But the choice in that commit to call troubleWatcher.close() seems broken.

troubleWatcher.close() does two things: binding.unwatch, and handleWatchers.remove. The latter is reasonable: we're trying to replace the old bogus HandleWatcher with the new one, so we should remove it, sure.

But binding.unwatch here is problematic: the argument we're passing to it is just the fd that we got back from binding.watch, which we're going to pass to close (Mac) or inotify_rm_watch (Linux). But... that means we're actually closing the fd we just got back from binding.watch and which is saved in the new HandleWatcher!

ie, this error case means we've suddenly learned that a HandleWatcher in handleWatchers contains an invalid WatcherHandle (fd). Going and calling close on that invalid handle is just going to break the new thing we got.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions