Fix SSE Transport Memory Leak #165
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.
When running the SSE transport in production, we noticed a massive memory leak. We have a Kubernetes health check process that was hitting the SSE endpoint periodically and then just disconnecting which was causing the memory leak. Digging in to the current implementation, there is no disconnection handling in the case of an abrupt disconnection, so this PR adds some cleanup when the connection drops.
Motivation and Context
Removes a memory leak in the case that a client disconnects abruptly.
How Has This Been Tested?
You can replicate the memory leak by simply making a GET request to the SSE endpoint and then disconnecting many times to see memory grow quite rapidly. I applied this fix to our production environment and the instance memory usage has been steady since.
Breaking Changes
No
Types of changes
Checklist
Additional context
There were two errors that were failing on main already, so these changes have not added any new errors.