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

Unpredictable behaviour in fasthttp.hijackConn after closure #1630

Closed
askolesov opened this issue Oct 4, 2023 · 1 comment
Closed

Unpredictable behaviour in fasthttp.hijackConn after closure #1630

askolesov opened this issue Oct 4, 2023 · 1 comment

Comments

@askolesov
Copy link
Contributor

Currently, the way fasthttp.hijackConn behaves is different from what can be expected with the net.Conn interface.

Normally, when you close a net.Conn, if you try to read or write again, you get errors.

But with fasthttp.hijackConn, when you close it, it gets cleaned and put back in the pool. If you try to read from or write to it again, it can cause two problems:

  1. If it hasn't been reused yet, it might cause null reference exception because the underlying connection is nil.
  2. If it has been reused, you might end up reading from or writing to a completely different connection, which is very bad.

I suggest not reusing hijackConn when KeepHijackedConns is enabled (it still will be reused when this option is disabled). This might make things a bit slower, but it will make the behavior more predictable for users.

We've had issues with this in our project, and it seems like the easiest way to fix them is with this pull request.

@askolesov
Copy link
Contributor Author

Here is the fix: #1629

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

No branches or pull requests

2 participants