[Merged by Bors] - fix: correct shutdown sequence for http server (ENG-87) #847
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.
Please read the full report here.
Put simply, we were seeing this Mongo Error:
![image](https://private-user-images.githubusercontent.com/5643574/339926335-35c030d4-3738-4134-a72c-f978a8e37282.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTkxOTQyMDgsIm5iZiI6MTcxOTE5MzkwOCwicGF0aCI6Ii81NjQzNTc0LzMzOTkyNjMzNS0zNWMwMzBkNC0zNzM4LTQxMzQtYTcyYy1mOTc4YThlMzcyODIucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDYyNCUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA2MjRUMDE1MTQ4WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9MjY3NDFjNTRlNDc4ODZjY2E0MmExMjliZWMyZDBlMGViNmY2ZDNlN2MzZGFjZDViZjVjNjViZWY0ZmMyMGQ5NyZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.VaUWBqOPKjC7gAHBuYU9XrMftRpGP1WgSAQys-Hore0)
'MongoNotConnectedError: Client must be connected before running operations
However, it was always occurring AFTER a
SIGTERM
event:This is because we were kill all client connections first (Mongo, Redis, etc), THEN we were stopping the server from accepting new connections.
What this means is that it was possible for a existing request to be executed, the mongo client to get closed, then for that request to try and make a call to mongo.
To reproduce the error locally, just checkout this commit/branch:
![Screenshot 2024-06-14 at 7 12 03 PM](https://private-user-images.githubusercontent.com/5643574/339927244-9f9ba100-5fc9-4647-89cc-a237ac861529.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTkxOTQyMDgsIm5iZiI6MTcxOTE5MzkwOCwicGF0aCI6Ii81NjQzNTc0LzMzOTkyNzI0NC05ZjliYTEwMC01ZmM5LTQ2NDctODljYy1hMjM3YWM4NjE1MjkucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDYyNCUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA2MjRUMDE1MTQ4WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9MmM2MzQ1YWYyZWUyMjg4ZGE2NTY2YmQwMWM0NDA0NGY2ZDVjNWM3MDRlYzE5YjY1ZmY1MDk5OTBhOWY3NTM1NCZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.LcBfH3FDso0sDWhzlxxqEar0CIeetXvLavNoiHLLLWc)
18f076c
mesh the service and try to make a API call that uses mongo to it within 30 seconds.