Ensure active connections is decremented #2335
Merged
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.
This PR is proposing an additional improvement for the original PR #2237.
While debugging another problem in HttpMetricsHandlerTest, I found that when the AbstractHttpServerMetricsHandler.write method is getting an exception thrown by recordWrite, then the recordInactiveConnection is never called, see here.
So, this is too bad because the long adder that is incremented from here is then never decremented by the missed call to recordInactiveConnection, resulting in leaving the number of active connections to an inconsistent value.
So, in HttpMetricsHandlerTest, when the testRecordingFailsServerSide or the testRecordingFailsClientSide are executed, and if the testServerConnectionsMicrometer is executed after, then it will fail because the number of active connections is left in a wrong state (after the testRecordingFailsServerSide or testRecordingFailsClientSide is executed):
Now, because we retry failed tests one time, then during the second round of test execution, we will only execute the testServerConnectionsMicrometer test which will succeed this time.
So, this PR slightly modify the original patch in order to ensure that we always call recordInactiveConnection from AbstractHttpServerMetricsHandler.write method even if recordWrite fails. It avoids leaving the number of active connections in an inconsistent state and it makes it easier to debug the HttpMetricsHandlerTest, without having to wait for some tests to be re-run alone , a second time.
Fixes #2187