Skip to content

Commit

Permalink
Fix body mus be closed before beeing discarded
Browse files Browse the repository at this point in the history
  • Loading branch information
phymbert committed Dec 7, 2024
1 parent 1707b57 commit deb3ed3
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ See the [K6 SSE Extension design](docs/design/021-sse-api.md).

## k6 version

This extension is tested with `k6` version `v0.55.0` last release is [v0.1.4](https://github.com/phymbert/xk6-sse/releases/tag/v0.1.4).
This extension is tested with `k6` version `v0.55.0` last release is [v0.1.5](https://github.com/phymbert/xk6-sse/releases/tag/v0.1.5).

## Build

Expand Down
7 changes: 2 additions & 5 deletions sse.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,16 +278,13 @@ func (c *Client) closeResponseBody() error {
var err error

c.shutdownOnce.Do(func() {
// Ensure response body is read in order for http tcp connection to be reused
_, err = io.Copy(io.Discard, c.resp.Body)
if err != nil {
c.handleEvent("error", c.rt.ToValue(err))
}
err = c.resp.Body.Close()
if err != nil {
c.handleEvent("error", c.rt.ToValue(err))
}
close(c.done)
// Ensure response body is read in order for http tcp connection to be reused
_, _ = io.Copy(io.Discard, c.resp.Body)
})

return err
Expand Down

0 comments on commit deb3ed3

Please sign in to comment.