Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix superfluous response call for WS request #51493

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

adone
Copy link

@adone adone commented Jan 27, 2025

what happened

we experienced some issues with WebSockets:

  • logs were saying
http: superfluous response.WriteHeader call from [go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp/internal/request.(*RespWriterWrapper](http://go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp/internal/request.(*RespWriterWrapper)).writeHeader (resp_writer_wrapper.go:80)
  • browser was getting 400 Bad Request without any error text in body

Investigation

we traced the error and found where status 400 can be returned during /webapi/sites/:site/connect/ws call:
https://github.com/gorilla/websocket/blob/v1.5.3/server.go#L125

it turned out we had a wrong configured proxy before teleport
so teleport was receiving WS connect requests without WS headers

so the first response.WriteHeader call happens here:
https://github.com/gorilla/websocket/blob/v1.5.3/server.go#L77
if authnWsUpgrader.Error is empty http.Error will be used with just a status text (400 Bad Request)
and the original error (missing WS headers) is lost

fix

the easiest fix is set Error function as empty function to prevent unplanned http.Error call
even the lib itself doing this https://github.com/gorilla/websocket/blob/v1.5.3/server.go#L299

@CLAassistant
Copy link

CLAassistant commented Jan 27, 2025

CLA assistant check
All committers have signed the CLA.

Copy link

github-actions bot commented Jan 27, 2025

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@adone
Copy link
Author

adone commented Jan 28, 2025

I have read the CLA Document and I hereby sign the CLA

when there is a wrong configured proxy before Teleport
it fails to return a proper error during WebSocket connect operation
because of response.WriteHeader duplicate call

first call is happened in the websocket.Upgrader's `returnError` function after WS headers mismatch
and it only sets status to 400 Bad Request without any text
https://github.com/gorilla/websocket/blob/v1.5.3/server.go#L77

Teleport tries to set the response status but fails to do that:
http: superfluous response.WriteHeader call
and the main reason of the error (missing WS headers) is lost
@adone adone force-pushed the fix-ws-superfluous-response branch from 09d773a to 62ead74 Compare January 28, 2025 12:55
@zmb3 zmb3 requested a review from tigrato January 30, 2025 00:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants