Repository navigation
Keep queue waits going when a masked interrupt wakes them - #10057
Conversation
6708e92 to
d6d94cf
Compare
Thread#raise and Thread#kill wake the waiting thread even inside Thread.handle_interrupt(Object => :never). Timed Queue#pop and timed and untimed SizedQueue#push gave up on that wakeup and raised ThreadError inside the masked block. Thread#wakeup hit the same path, so it cut timed waits short with ThreadError. Loop like the untimed pop task and CRuby's queue_do_pop and rb_szqueue_push: check interrupts, then wait again, for the rest of the timeout if there is one. Part of jruby#10028.
The timed pop and push tasks each had their own copy of the loop that runs unmasked interrupts and waits again. Move it into Queue.retryInterruptedWait. The untimed tasks keep the loop written out, because a capturing lambda there allocates on every pop and push. Annotate each task with the part of queue_do_pop or rb_szqueue_push it ports.
Untimed pop and push already kept their own loops, because a capturing lambda there allocates on every call. That left the helper with only the two timed tasks. Write their loops out too, and explain the retry once on BLOCKING_TAKE_TASK.
737e421 to
ecde274
Compare
|
I tried to refactor the loop to a helper but it would require passing a lambda which made it slow or making it complicated so keeping the loops as is. It would be nice to have the |
headius
left a comment
There was a problem hiding this comment.
Yup, this is the correct handling of JVM thread interrupts.
Hmmm, maybe. In a few months we'll roll a new LTS based on 10.1 and it won't matter as much. I think it might be messier than it's worth (@zev did several iterations cleaning up mismatched CRuby comments and it probably wouldn't be a trivial backport). |
|
I could see a compromise where we just backport the annotation and not the extra work to clean up existing comments; at least new patches to 10.0 could use the annotation and not pollute 10.1+ when merged forward. @sampokuokkanen I'll do that in a separate PR and fix these couple of comments then. |
Fixes the queue part of #10028.
Inside
Thread.handle_interrupt(Object => :never),Thread#raiseandThread#killstill wake a thread that waits on a queue. Three waits gave up on that wakeup. They raisedThreadError("interrupted in Thread::Queue#pop") inside the masked block, and then the deferred interrupt replaced it when the block ended:Queue#pop(timeout:)SizedQueue#push(x, timeout:)SizedQueue#push(x)without a timeoutThread#wakeuptook the same path, so it also ended timed waits early withThreadError.CRuby keeps waiting in both cases:
queue_do_pop,rb_szqueue_push.Not fixed here:
sleepreturns early on JRuby (the other part of Queue#pop(timeout:)andSizedQueue#push(timeout:)receiveThread#kill/Thread#raiseinsideThread.handle_interrupt(Object => :never) #10028). That will be a separate PR.Thread#statusafterThread#wakeup: a thread still waiting inQueue#popreports"run". CRuby reports"sleep".ConditionVariable#wait: it returns the condition variable on JRuby and an Integer on CRuby.