Allow heartbeat to restart the pipe thread with only sync commands #2965
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.
There is a thread looping in the method
PhysicalConnection.ReadFromPipe
to process response from Redis, match them with the sent command and signaling the completion of the message. If this thread has an exception, its catch block will callRecordConnectionFailed
which will proceed to restart a new thread to continue reading Redis responses.However, if another exception occurred in the catch before the new thread can be started (in a case of high memory pressure, OOM exceptions can happen anywhere) we are in a state where no one is reading the pipe of Redis responses, and all commands sent end in timeout.
If at least one async command is sent, the heartbeat thread will detect the timeout in the
OnBridgeHeartbeat
method, and if no read were perform for 4 heartbeat it will issue a connection failure. However, no such protection were in place if only sync commands are sent. In this case, they were all ending in timeout without any mechanisms to start reading their responses again.In this PR, the heartbeat thread will check timeouts for sync commands as well. Therefore, it will be able to start the thread looping in
ReadFromPipe
even if only sync commands are sent, ensuring we will not reach a state were all commands end in timeout.This PR is loosely linked to the issue #2919, as this problem and its correction were found during investigation of the issue.