Skip to content

Conversation

@charkost
Copy link
Contributor

@charkost charkost commented Jun 14, 2021

All client unix sockets are initiated at the spring application process before forking to serve each client.
A reference to the client socket remains active by the thread in the wait method waiting for the client's fork to exit.

This is problematic in cases with more than one parallel clients because the client socket for the first client is also present
in the fork for the second client due to fd inheritance from the spring application parent process.

With the first client's socket being present in the second client's fork, the first client cannot exit gracefully because
a reference to its socket remains open in the fork for the second client leading to rails console hanging
for the first client until the second client gets terminated:

status = application.read.to_i
log "got exit status #{status}"
exit status

For read to return & release the client, all references to the socket should be closed.

The problem can be reproduced by opening 2 rails consoles on spring & attempting to exit the first console while
the second is still active.

@charkost charkost changed the title Close other client sockets in application forks Close other client sockets in spring application forks Jun 14, 2021
All client unix sockets are initiated at the spring application
process before forking to serve each client. A reference to the
client socket remains active by the thread in the wait method waiting
for the client's fork to exit.

This is problematic in cases with more than one parallel clients
because the client socket for the first client is also present in
the fork for the second client due to fd inheritance from the spring
application parent process.

With the first client's socket being present in the second client's
fork, the first client cannot exit gracefully because a reference to
its socket remains open in the fork for the second client leading to
rails console hanging for the first client until the second client
gets terminated.

The problem can be reproduced by opening 2 rails consoles on spring
& attempting to exit the first console while the second is still active.
@charkost charkost force-pushed the fix_console_hanging branch from 96cba83 to 1c15dcd Compare June 15, 2021 09:06
@charkost charkost changed the title Close other client sockets in spring application forks Fix hanging consoles: Close other client sockets in spring application forks Jun 25, 2021
@rafaelfranca rafaelfranca merged commit 6bba044 into rails:master Nov 23, 2021
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