forked from phoenixframework/phoenix
-
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.
Allow returning custom error code from socket connect
Previously there were only two options, `{:ok, socket}` and `:error`. The error always returned `403 Forbidden` to the user. This is quite limiting. In our use case, we do rate limiting in the connect function. E.g. if one of the phoenix servers goes down or restarts, then we cannot immediately handle tens of thousands of users connecting at the same time. Instead we let in some users, and let others reconnect later. Also if we're under a heavy load then we want to limit users connecting. "Forbidden" is not a good status code for us. It indicates that something is likely wrong with the access token / authorization. In that case we want user to refresh the access token and reconnect. However if we're under heavy load, we want to say user to try again much later. E.g. maybe return 429 or 503 status code. This commit allows now returning `{:error, status}` in the Socket#connect function. It is backwards compatible: just `:error` is still mapped to Forbidden.
- Loading branch information
Showing
6 changed files
with
46 additions
and
9 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
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
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
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
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
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