forked from ppy/osu-server-spectator
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix incorect connection metrics tracking on instances pending shutdown
While a spectator server instance was pending shutdown, it could start reporting endlessly rising user counts until its actual shutdown. The reason for this was questionable logic in `ConcurrentConnectionLimiter`. When I wrote that thing I used `try...finally` in `OnConnectedAsync()` and `OnDisconnectedAsync()` because I wanted to have multiple returns in the body of the method and sitll call `await next()` at the end. However I appear to have also forgotten that it means that `await next()` would be called _even if the preceding code threw an exception_, and then _the exception would be thrown anyway_. This in the case of `StatefulUserHub`s led to the following sequence of events: 1. `ConcurrentConnectionLimiter.OnConnectedAsync()` fires 2. It dies on its innards, but because of the `finally`, calls `await next()` anyway 3. Inside `await next()` is the hub's connection method, in particular `LoggingHub.OnConnectedAsync()`, which increments the datadog connected user gauge 4. Then after the finally, because any exception that was thrown was not caught, it will get _rethrown_, interrupting the connection flow 5. After this, `OnDisconnectedAsync()` will not get called for this connection, leading the counter to not decrement back down from the increment in point (3) leading to the runaway increase in reported user counts. To fix, stop using `try...finally` and split the blocks of code that want early-returns to separate methods instead.
- Loading branch information
Showing
1 changed file
with
61 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters