Fix server hang when trying to stop a server with active connections with event notifications #8432
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The reason for the hang is that we handle
port_async
in a strange way. When we create it inaux_request()
it is added to chain of client ports (port_clients
) viaalloc_port()
, but is not added toinet_ports
.inet_ports
used inPortsCleanup::closePorts()
when we start shutdown server to close ports that we currently have. So, after closing all client ports, exceptport_async
, we start looping over these active ports inselect_multi()
, hoping to get some data from them. This is happens becauseport_async
is presented inport_clients
chain and hasport_state = PENDING
.My fix for this problem is to close
port_async
when we close it's parent port.The hang can be reproduced by running
example/api/api16
and making one more additional connection to the database, then try to kill the server, it will hang with inability to receive new connections, it can only be stopped withkill -9
.This bug can also be reproduced in v5.0, I haven't tested it in older versions, but it seems the code is the same.