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
First interrupt a thread. Stop it if that doesn't work #163
Conversation
2255b47
to
88ecd0c
Compare
Hi. Nice work! A default of 100ms seems a little bit on the low end to me. From the perspective of a UI client (like CIDER), you would typically interrupt when something takes too long, right? So I guess an additional second or 2 of waiting wouldn't be a problem in that case. For my use case, 5 seconds would be fine. Just another thought: how hard would be to encode the timeout in the actual message (sorry, not too familiar with nrepl)? In that case you can let the client decide. |
I also realised we don't actually need to wait for the thread to terminate or stop before returning on the interrupt call, so something like a 5s wait time wouldn't slow things down on the client side. The timeout is really "what's the cap on CPU time wasted on an eval after you interrupt it". @bbatsov : your thoughts on adding this timeout as something the client can specify? |
I'm on the fence about this. It really depends on whether we can agree that some default is good enough for most cases. |
I'm fiddling a version that does the wait-and-stop asynchronously. If we can get that to work with say, a 5s timeout, that might provide a good enough default behaviour that we won't need to add a customisable parameter for now? |
4a39579
to
94fe66d
Compare
Ok. Updated this to work as follows:
I think this set of behaviours strikes a balance between allowing a thread to respond to an interrupt, but also ensuring we actually kill runaway processes. The 5000ms is from discussion above, and 100ms chosen to not slow down the response too much. I can imagine someone wanting different values for their particular application, but that feels speculative. The build is failing because of a network issue with the master build of clojure. |
035c201
to
80360a3
Compare
80360a3
to
a0f20e9
Compare
Thanks! |
Fixes #158
Right now, an interrupt first calls
Thread.interrupt()
. It waits 100ms for the thread to terminate itself. Failing that, it callsThread.stop()
. This gives code that respects the interrupt flag a chance to exit in a more safe manner.A few things to note:
Thread.sleep()
throws anInterruptedException
when interrupted. This causes aneval-error
if not otherwise handled. One test has been updated to reflect this. This does change nREPL's behaviour. I'm not sure how much of an issue this could be?I think this provides us a way to deal with the #132, where a an interrupted eval with streamed printing can generate malformed bencode. Not too sure how that should be done though.