dgrr / http2

HTTP/2 implementation for fasthttp
Apache License 2.0
210 stars 37 forks source link

Fix response writer goroutine leaks and channel block #46

Closed cachalots closed 2 years ago

cachalots commented 2 years ago

If the client closes the connection directly without catching the error, the writer's channel will block and the goroutine will leak.

dgrr commented 2 years ago

How do you know the coroutine leaks? The problem you are trying to solve is: After writing, the coroutine might leak if an error returns. But, if there's any error related to the connection (for example, connection closed), then, we'll receive that same error on the readLoop coroutine, and that will close all the channels. Right?

Correct me if you think I am wrong.

cachalots commented 2 years ago

For example, connection closed, if response fr length > 128 (sc.writer length), serverConn.handleEndRequest will block at sc.writer <- fr, causing serverConn.handleStreams's read loop to be blocked and the channel will not be released properly.

dgrr commented 2 years ago

That's right. Thanks for your PR!