Skip to content

Commit 3f8c815

Browse files
committed
fix: wsNetConn cancel on any error
1 parent ef439fe commit 3f8c815

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"
@@ -510,23 +509,23 @@ func convertWorkspaceAgent(dbAgent database.WorkspaceAgent, agentUpdateFrequency
510509
}
511510

512511
// wsNetConn wraps net.Conn created by websocket.NetConn(). Cancel func
513-
// is called if io.EOF is encountered.
512+
// is called if a read or write error is encountered.
514513
type wsNetConn struct {
515514
cancel context.CancelFunc
516515
net.Conn
517516
}
518517

519518
func (c *wsNetConn) Read(b []byte) (n int, err error) {
520519
n, err = c.Conn.Read(b)
521-
if errors.Is(err, io.EOF) {
520+
if err != nil {
522521
c.cancel()
523522
}
524523
return n, err
525524
}
526525

527526
func (c *wsNetConn) Write(b []byte) (n int, err error) {
528527
n, err = c.Conn.Write(b)
529-
if errors.Is(err, io.EOF) {
528+
if err != nil {
530529
c.cancel()
531530
}
532531
return n, err
@@ -538,8 +537,8 @@ func (c *wsNetConn) Close() error {
538537
}
539538

540539
// websocketNetConn wraps websocket.NetConn and returns a context that
541-
// is tied to the parent context and the lifetime of the conn. A io.EOF
542-
// error during read or write will cancel the context, but not close the
540+
// is tied to the parent context and the lifetime of the conn. Any error
541+
// during read or write will cancel the context, but not close the
543542
// conn. Close should be called to release context resources.
544543
func websocketNetConn(ctx context.Context, conn *websocket.Conn, msgType websocket.MessageType) (context.Context, net.Conn) {
545544
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