Skip to content

Commit 9e6727e

Browse files
committed
fix: wsNetConn cancel on any error
1 parent e0a2f8e commit 9e6727e

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

coderd/workspaceagents.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"context"
55
"database/sql"
66
"encoding/json"
7-
"errors"
87
"fmt"
98
"io"
109
"net"
@@ -521,23 +520,23 @@ func convertWorkspaceAgent(dbAgent database.WorkspaceAgent, agentUpdateFrequency
521520
}
522521

523522
// wsNetConn wraps net.Conn created by websocket.NetConn(). Cancel func
524-
// is called if io.EOF is encountered.
523+
// is called if a read or write error is encountered.
525524
type wsNetConn struct {
526525
cancel context.CancelFunc
527526
net.Conn
528527
}
529528

530529
func (c *wsNetConn) Read(b []byte) (n int, err error) {
531530
n, err = c.Conn.Read(b)
532-
if errors.Is(err, io.EOF) {
531+
if err != nil {
533532
c.cancel()
534533
}
535534
return n, err
536535
}
537536

538537
func (c *wsNetConn) Write(b []byte) (n int, err error) {
539538
n, err = c.Conn.Write(b)
540-
if errors.Is(err, io.EOF) {
539+
if err != nil {
541540
c.cancel()
542541
}
543542
return n, err
@@ -549,8 +548,8 @@ func (c *wsNetConn) Close() error {
549548
}
550549

551550
// websocketNetConn wraps websocket.NetConn and returns a context that
552-
// is tied to the parent context and the lifetime of the conn. A io.EOF
553-
// error during read or write will cancel the context, but not close the
551+
// is tied to the parent context and the lifetime of the conn. Any error
552+
// during read or write will cancel the context, but not close the
554553
// conn. Close should be called to release context resources.
555554
func websocketNetConn(ctx context.Context, conn *websocket.Conn, msgType websocket.MessageType) (context.Context, net.Conn) {
556555
ctx, cancel := context.WithCancel(ctx)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy