Skip to content

Send 1000 on {:shutdown, :disconnected}#576

Merged
mtrudel merged 2 commits intomtrudel:mainfrom
wwitek-whatnot:disconnect_as_normal_stop
Mar 26, 2026
Merged

Send 1000 on {:shutdown, :disconnected}#576
mtrudel merged 2 commits intomtrudel:mainfrom
wwitek-whatnot:disconnect_as_normal_stop

Conversation

@wwitek-whatnot
Copy link
Copy Markdown
Contributor

Background

We currently use Cowboy in our production system and tried switching to Bandit. This turned out to not be possible, as we started getting errors on client side, due to sockets being closed with code 1011.
After some investigation we found that this is because we broadcast "disconnect" to the id socket channel, in order to disconnect all user's sockets (as in this example). In Bandit this goes to catch-all {:stop, reason, websock_state}, while in Cowboy, this goes through adapter here and so is then interpreted as a normal stop reason.
This is also very easy to reproduce by just generating two new phoenix apps with a single channel, one using cowboy and one using bandit. Then have a client join the channel, have an :after_join self-sent message trigger a disconnect, and observe the code on the client.

Proposed change

We'd like to add {:shutdown, :disconnected} as one of the cases with 1000 code on close, as we believe this would fall under "socket being closed because it's purpose has been fulfilled" as defined in the RFC and definitely doesn't fit 1011's "server is terminating the connection because it encountered an unexpected condition that prevented it from fulfilling the request".

@mtrudel
Copy link
Copy Markdown
Owner

mtrudel commented Mar 25, 2026

LGTM! There's a small credo error on code complexity coming out of this; I'll get it resolved and merged later today.

Thanks for the PR!

@mtrudel mtrudel merged commit 2a809d5 into mtrudel:main Mar 26, 2026
25 of 28 checks passed
@mtrudel
Copy link
Copy Markdown
Owner

mtrudel commented Mar 26, 2026

Published as 1.10.4!

@wwitek-whatnot
Copy link
Copy Markdown
Contributor Author

Published as 1.10.4!

Thank you!

jimsynz pushed a commit to jimsynz/neonfs that referenced this pull request Mar 29, 2026
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [bandit](https://hex.pm/packages/bandit) ([source](https://github.com/mtrudel/bandit)) | prod | patch | `1.10.3` → `1.10.4` |

---

### Release Notes

<details>
<summary>mtrudel/bandit (bandit)</summary>

### [`v1.10.4`](https://github.com/mtrudel/bandit/blob/HEAD/CHANGELOG.md#1104-25-Mar-2026)

[Compare Source](mtrudel/bandit@1.10.3...1.10.4)

##### Enhancements

- Support `{:shutdown, :disconnected}` as a normal WebSocket result code ([#&#8203;576](mtrudel/bandit#576), thanks [@&#8203;wwitek-whatnot](https://github.com/wwitek-whatnot)!)

</details>

---

### Configuration

📅 **Schedule**: Branch creation - Between 12:00 AM and 03:59 AM ( * 0-3 * * * ) in timezone Pacific/Auckland, Automerge - Between 12:00 AM and 03:59 AM ( * 0-3 * * * ) in timezone Pacific/Auckland.

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0My45MC4xIiwidXBkYXRlZEluVmVyIjoiNDMuOTAuMSIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOlsicmVub3ZhdGUiXX0=-->

Reviewed-on: https://harton.dev/project-neon/neonfs/pulls/83
Co-authored-by: Renovate Bot <bot@harton.nz>
Co-committed-by: Renovate Bot <bot@harton.nz>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants