Skip to content

Commit 505cd04

Browse files
committed
fix: use a native websocket.NetConn for agent RPC client
1 parent 094ce97 commit 505cd04

File tree

1 file changed

+4
-18
lines changed

1 file changed

+4
-18
lines changed

codersdk/agentsdk/agentsdk.go

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"encoding/json"
66
"fmt"
77
"io"
8-
"net"
98
"net/http"
109
"net/http/cookiejar"
1110
"net/url"
@@ -206,14 +205,11 @@ func (c *Client) ConnectRPC(ctx context.Context) (drpc.Conn, error) {
206205
return nil, codersdk.ReadBodyAsError(res)
207206
}
208207

209-
_, wsNetConn := codersdk.WebsocketNetConn(ctx, conn, websocket.MessageBinary)
208+
// Set the read limit to 4 MiB -- about the limit for protobufs. This needs to be larger than
209+
// the default because some of our protocols can include large messages like startup scripts.
210+
conn.SetReadLimit(1 << 22)
211+
netConn := websocket.NetConn(ctx, conn, websocket.MessageBinary)
210212

211-
netConn := &closeNetConn{
212-
Conn: wsNetConn,
213-
closeFunc: func() {
214-
_ = conn.Close(websocket.StatusGoingAway, "ConnectRPC closed")
215-
},
216-
}
217213
config := yamux.DefaultConfig()
218214
config.LogOutput = nil
219215
config.Logger = slog.Stdlib(ctx, c.SDK.Logger(), slog.LevelInfo)
@@ -618,13 +614,3 @@ func LogsNotifyChannel(agentID uuid.UUID) string {
618614
type LogsNotifyMessage struct {
619615
CreatedAfter int64 `json:"created_after"`
620616
}
621-
622-
type closeNetConn struct {
623-
net.Conn
624-
closeFunc func()
625-
}
626-
627-
func (c *closeNetConn) Close() error {
628-
c.closeFunc()
629-
return c.Conn.Close()
630-
}

0 commit comments

Comments
 (0)