Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raise a ruby exception for InvalidWatchSignature #757

Merged
merged 4 commits into from
Jan 23, 2017

Conversation

surenm
Copy link
Contributor

@surenm surenm commented Dec 29, 2016

Addresses #512

Some how the runtime error thrown in evma_unwatch_filename was not caught and EM crashed with std::runtime_error. A Simple patch to fix this by throwing a ruby exception instead.

Not sure if this is the correct fix but at least the ruby exception can be caught and handled further.

@surenm
Copy link
Contributor Author

surenm commented Dec 29, 2016

Not sure why the travis build failed, didn't seem like a related failure. If it is related, can you please help me with fixing it?

@sodabrew
Copy link
Member

sodabrew commented Jan 1, 2017

The build failure was unrelated, I just re-ran the build so you can see your code turns up green.

This looks good! I have a suggestion/request for a change: The signatures system is used by more than just file watching, so I think the exception should be called InvalidSignature and then it can use it everywhere that a signature argument is used.

@sodabrew sodabrew added this to the v1.3.0 milestone Jan 1, 2017
@surenm
Copy link
Contributor Author

surenm commented Jan 2, 2017

Thanks for getting back quickly! Made the refactor and added a unit test case as well 👍

file = Tempfile.new('foo')

w1 = EventMachine.watch_file(file.path)
w2 = EventMachine.watch_file(file.path)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This returns a real Watcher object that isn't valid? That seems bad, like, the better solution here is to return nil if the file is already being watched and we can't watch it a second time.

In the case of kqueue, does it actually create two independent watchers?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The watcher it returns is valid but the binding to watch map that is used to keep reference of the watch is not properly updated, so stopping the watch raises this error.

The inotify and kqueue behaviour is reported more thoroughly in #512.

evma_unwatch_filename(NUM2BSIG (sig));
} catch (std::runtime_error e) {
rb_raise (EM_eInvalidSignature, "%s", e.what());
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with this regardless of the reason for the invalid signature; raising a C++ exception into Ruby space that kills the application isn't helpful to anybody.

@sodabrew sodabrew modified the milestones: v1.2.2, v1.3.0 Jan 23, 2017
@sodabrew sodabrew merged commit 05df744 into eventmachine:master Jan 23, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants