Skip to content

Stop client process and clean up if client disconnects#4737

Closed
nickva wants to merge 1 commit into
mainfrom
jenkins-monitor-client-socket-for-disconnections
Closed

Stop client process and clean up if client disconnects#4737
nickva wants to merge 1 commit into
mainfrom
jenkins-monitor-client-socket-for-disconnections

Conversation

@nickva
Copy link
Copy Markdown
Contributor

@nickva nickva commented Aug 24, 2023

Draft version of the PR #4736 to test running the full CI.

Previously, when processing long running streaming requests, such as _find with
a highly selective selector, when no rows are emitted for a while, the client
could disconnect but the request process, and all the associated workers on
remote nodes would continue running, consuming server resources.

We already handle remote (RPC) process cleanup if the coordinator crashes, we
just need a way to kill that coordinator if the connection is closed in the
case when no data may be emitted for a long time. This is what the current
commit accomplishes.

It turns out there is no simple way to detect passive mode socket disconnects
in current versions of Erlang/OTP. The socket at the kernel level may be closed
(in close_wait state), however `inet:info/1` will continue reporting it as
`connected`. The only ways to obtain an accurate connection state is to try to
write, read, or query the TCP info state.

Here we attempt to query the state with tcp_info. Unfortunately, not all
versions of supported OTP platforms have this option, so it probably never
became an officially supported inet socket option, so we use `raw` socket
option for it. However, it turns out most of CouchDB supported platforms do
have that option. The only platform this is not working currently is Windows.
In that case, or future platform cases we default to the previous behavior,
assuming the socket is still open.

Co-Authored-By: Robert Newson <rnewson@apache.org>
@nickva nickva closed this Aug 24, 2023
@nickva nickva deleted the jenkins-monitor-client-socket-for-disconnections branch September 29, 2023 02:38
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.

1 participant