Skip to content

Commit 3fc21a9

Browse files
committed
fix: close HTTP response body on WebSocket dial failure
1 parent b97d5b8 commit 3fc21a9

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

lib/cp.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ func CpToInstance(ctx context.Context, cfg CpConfig, opts CpToInstanceOptions) e
157157
ws, resp, err := dialer.DialContext(ctx, wsURL, headers)
158158
if err != nil {
159159
if resp != nil {
160+
defer resp.Body.Close()
160161
body, _ := io.ReadAll(resp.Body)
161162
return fmt.Errorf("websocket connect failed (HTTP %d): %s", resp.StatusCode, string(body))
162163
}
@@ -358,6 +359,7 @@ func CpFromInstance(ctx context.Context, cfg CpConfig, opts CpFromInstanceOption
358359
ws, resp, err := dialer.DialContext(ctx, wsURL, headers)
359360
if err != nil {
360361
if resp != nil {
362+
defer resp.Body.Close()
361363
body, _ := io.ReadAll(resp.Body)
362364
return fmt.Errorf("websocket connect failed (HTTP %d): %s", resp.StatusCode, string(body))
363365
}

0 commit comments

Comments
 (0)