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

middlewear.Recover causes undefined behaviour if a connection has been upgraded. #661

Closed
tracplus-hpaterson opened this issue Sep 23, 2021 · 3 comments · Fixed by #795
Closed
Assignees

Comments

@tracplus-hpaterson
Copy link

tracplus-hpaterson commented Sep 23, 2021

The middlewear.Recover method attempts to write an HTTP 500 Internal Server Error to a response as part of the error recovery process. This will cause apparently undefined behavior if the connection has been hijacked.

In our use case, we have upgraded our connection to a WebSocket using golang.org/x/net/websocket/websocket.Handler to hijack the connection. A bug in our WebSocket handler, specifically a null pointer error, cause Chi to call Recover. The attempt to write to the upgraded connection after hijack caused apparently undefined behaviour: Internal variables were written down the WebSocket to the client, and the Go runtime reported a generic panic, reducing the diagnosting use of the Recover method.

Can we suggest the Recover method test if the connection has been upgraded or hijacked, and alter it's behavior appropriate - for example not trying to write to the HTTP connection, and possible providing an error over the WebSocket?

@pkieltyka
Copy link
Member

pkieltyka commented Sep 23, 2021 via email

@fatelei
Copy link
Contributor

fatelei commented Feb 5, 2023

does this issue have been resovled?if not,it can assign to me

@pkieltyka
Copy link
Member

@fatelei thank you :)

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 a pull request may close this issue.

3 participants