sse icon indicating copy to clipboard operation
sse copied to clipboard

Connection leaks if the statusCode not equals with 200

Open tigerlee opened this issue 3 years ago • 2 comments

Description

When I subscribes to a server, and it's returns me with status code 401, from the code we can see the req.Body didn't closed properly.

Workaround

Use a custom ResponseValidator like below can avoid at user side:

sseClient.ResponseValidator = func(c *sse.Client, resp *http.Response) error {
	if resp.StatusCode != 200 {
		resp.Body.Close()
		return fmt.Errorf("could not connect to stream: %s", http.StatusText(resp.StatusCode))
	}
	return nil
}

tigerlee avatar Sep 02 '21 08:09 tigerlee

Hi @tigerlee

Thanks for raising the issue! This should now be fixed in v2.3.6

purehyperbole avatar Sep 03 '21 17:09 purehyperbole

should this issue be closed then?

ss89 avatar Apr 24 '22 15:04 ss89