Skip to content

Terminate and await signal executor to avoid races with at_exit.#5614

Closed
headius wants to merge 3 commits intojruby:masterfrom
headius:signal_atexit_thread
Closed

Terminate and await signal executor to avoid races with at_exit.#5614
headius wants to merge 3 commits intojruby:masterfrom
headius:signal_atexit_thread

Conversation

@headius
Copy link
Member

@headius headius commented Feb 12, 2019

This restores #5441 for additional work before it is merged or dropped.

This avoids races due to the signal traps running on the JVM's
signal-handling thread while we run at_exit blocks on JRuby's
main thread.

Fixes jruby#5437.
@headius headius added this to the JRuby 9.2.7.0 milestone Feb 12, 2019
@headius
Copy link
Member Author

headius commented Feb 12, 2019

This looks like it might go green, but it was responsible for a verbose error being logged on master when a Fiber executor job was rejected.

@headius
Copy link
Member Author

headius commented Apr 8, 2019

The issues with the original PR are explained here: #5437 (comment)

We'll get this into 9.2.8

@headius headius modified the milestones: JRuby 9.2.7.0, JRuby 9.2.8.0 Apr 8, 2019
@headius headius modified the milestones: JRuby 9.2.8.0, JRuby 9.2.9.0 Aug 12, 2019
@headius
Copy link
Member Author

headius commented Oct 27, 2019

@Adithya-copart I'm not sure where we left this. I filed these changes before you came back with #5437 (comment) and suggested the original issue be closed. Is the additional work in this PR no longer necessary?

@headius headius removed this from the JRuby 9.2.9.0 milestone Oct 28, 2019
@headius
Copy link
Member Author

headius commented Oct 28, 2019

Detargeting since it's unclear if this is appropriate or necessary. Will be closed without further follow-up.

@Adithya-copart
Copy link

@headius This PR is no longer necessary as the main thread actually waits for the signal executors.

The issue I came across is that the main thread is being shutdown within the trap handlers. The at_exit blocks were partially executed which I mistakenly assumed to be a race condition between traps and at_exit handlers.

It was later fixed in puma here.

Signal.trap('INT') {p 'In trap'; Thread.main.kill; exit}

at_exit do
  # This gets printed
  p 'Inside at exit...'
  sleep 2
  # Never gets printed
  p 'Finished..'
end
p 'sleeping...'

sleep

@headius
Copy link
Member Author

headius commented Dec 10, 2019

@Adithya-copart Ok thank you. We are debating whether to include PR #5918 which might help such situations by warning that there's unterminated threads at exit.

@headius headius closed this Dec 10, 2019
@headius headius added this to the Invalid or Duplicate milestone Dec 10, 2019
@headius headius deleted the signal_atexit_thread branch December 10, 2019 03:36
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