Skip to content

server: preserve websocket close code when proxying to outposts - #26090

Merged
BeryJu merged 3 commits into
goauthentik:mainfrom
robisonjoel:fix/ws-proxy-preserve-close-code
Sep 14, 2026
Merged

BeryJu merged 3 commits into
goauthentik:mainfrom
robisonjoel:fix/ws-proxy-preserve-close-code

Conversation

@robisonjoel

Copy link
Copy Markdown
Contributor

Details

What does this PR change?

The server's websocket reverse proxy (src/server/core.rs, handle_websocket_connection) relays every close frame as Message::Close(None), dropping the original status code and reason. This forwards the received close frame unchanged instead, in both directions.

Why is this change needed?

When a web worker is recycled (web.max_requests) or the server restarts, uvicorn closes the outpost websocket gracefully with code 1012 (service restart). The proxy relayed a code-less close, so the outpost saw websocket: close 1005 (no status) and logged it at warning level — indistinguishable from a real fault. On a busy instance every recycle produces one, tripping false "outpost disconnected" alerts even though the outpost reconnects normally. The reverse direction dropped the outpost's own close code too.

How was this tested?

  • cargo test --bin authentik server::core::websockets — existing proxy tests pass.
  • On a live 2026.8.2 instance (this patched binary over the stock image): set web.max_requests=100, sent ~800 requests to force worker recycles, and confirmed the outposts logged websocket: close 1012 on each recycle. The same recycles produced close 1005 (no status) before the patch.

Linked issues

None — happy to open one if preferred.


AI assistance: root-cause analysis and the patch were done with AI (Claude), reviewed and tested by me. I understand the change and take responsibility for it.

I'm also happy to send a follow-up PR making the outpost log expected close codes (1012/1001) at debug rather than warning, which clears the remaining alert noise.

Checklist

  • Changed Rust package builds and its tests pass (cargo test --bin authentik server::core::websockets); full make all not run locally — CI covers it.
  • No documentation changes needed.
  • I have read the AI usage policy.

The websocket proxy that bridges outpost connections to the gunicorn/uvicorn
backend replaced every relayed close frame with a code-less close
(`Message::Close(None)`), discarding the status code and reason from the peer.

When a web worker is recycled (routinely, via web.max_requests) or restarted on
upgrade, uvicorn closes the outpost websocket gracefully with 1012 (service
restart). Because the proxy relayed `Close(None)`, the outpost instead received a
close frame with no status code, which surfaces as `websocket: close 1005 (no
status)` and is logged at warning level - indistinguishable from a genuine fault,
so a healthy deployment warns on every recycle and trips outpost-disconnect
alerting. The reverse direction stripped the outpost's own close code too.

Relay the received close frame verbatim in both directions so the peer sees the
real close code and reason. The tail-of-stream case (peer closes without sending
a Close frame) still sends `Close(None)`, which is correct.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@robisonjoel
robisonjoel requested a review from a team as a code owner September 13, 2026 16:52
@netlify

netlify Bot commented Sep 13, 2026

Copy link
Copy Markdown

✅ Deploy Preview for authentik-docs ready!

Name Link
🔨 Latest commit be3e61e
🔍 Latest deploy log https://app.netlify.com/projects/authentik-docs/deploys/6aa6d4d4692ceb0008791f92
😎 Deploy Preview https://deploy-preview-26090--authentik-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Signed-off-by: Jens Langhammer <[email protected]>
@BeryJu BeryJu added the backport/version-2026.8 Add this label to PRs to backport changes to version-2026.8 label Sep 14, 2026
@codecov

codecov Bot commented Sep 14, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.84%. Comparing base (db62795) to head (3fa038f).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/server/core.rs 0.00% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #26090      +/-   ##
==========================================
- Coverage   91.88%   91.84%   -0.04%     
==========================================
  Files        1171     1171              
  Lines       75613    75615       +2     
  Branches     4054     4056       +2     
==========================================
- Hits        69475    69452      -23     
- Misses       6096     6121      +25     
  Partials       42       42              
Flag Coverage Δ
conformance 33.71% <ø> (+<0.01%) ⬆️
e2e 38.38% <ø> (+<0.01%) ⬆️
integration 29.98% <ø> (-0.45%) ⬇️
rust 42.89% <0.00%> (-0.03%) ⬇️
unit 93.44% <ø> (ø)
unit-migrate 93.46% <ø> (+7.33%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

@BeryJu
BeryJu merged commit fce697d into goauthentik:main Sep 14, 2026
137 of 138 checks passed
@authentik-cherry-pick

Copy link
Copy Markdown
Contributor

🍒 Cherry-pick to version-2026.8 created: #26132

BeryJu added a commit that referenced this pull request Sep 14, 2026
…ry-pick #26090 to version-2026.8) (#26132)

server: preserve websocket close code when proxying to outposts (#26090)

* server: preserve websocket close code when proxying to outposts

The websocket proxy that bridges outpost connections to the gunicorn/uvicorn
backend replaced every relayed close frame with a code-less close
(`Message::Close(None)`), discarding the status code and reason from the peer.

When a web worker is recycled (routinely, via web.max_requests) or restarted on
upgrade, uvicorn closes the outpost websocket gracefully with 1012 (service
restart). Because the proxy relayed `Close(None)`, the outpost instead received a
close frame with no status code, which surfaces as `websocket: close 1005 (no
status)` and is logged at warning level - indistinguishable from a genuine fault,
so a healthy deployment warns on every recycle and trips outpost-disconnect
alerting. The reverse direction stripped the outpost's own close code too.

Relay the received close frame verbatim in both directions so the peer sees the
real close code and reason. The tail-of-stream case (peer closes without sending
a Close frame) still sends `Close(None)`, which is correct.



* no claude comments



---------

Signed-off-by: Jens Langhammer <[email protected]>
Co-authored-by: The Ginger <[email protected]>
Co-authored-by: Claude Opus 4.8 <[email protected]>
Co-authored-by: Jens Langhammer <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport/version-2026.8 Add this label to PRs to backport changes to version-2026.8

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants