Skip to content

Commit f1544dd

Browse files
committed
Cherry-picks #15898 and #15927 to backport the fix to #15616
--------------------- chore: migrate to coder/websocket 1.8.12 (#15898) Migrates us to `coder/websocket` v1.8.12 rather than `nhooyr/websocket` on an older version. Works around coder/websocket#504 by adding an explicit test for `xerrors.Is(err, io.EOF)` where we were previously getting `io.EOF` from the netConn.
1 parent 6125358 commit f1544dd

32 files changed

+52
-107
lines changed

coderd/healthcheck/websocket.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ import (
1010
"time"
1111

1212
"golang.org/x/xerrors"
13-
"nhooyr.io/websocket"
1413

1514
"github.com/coder/coder/v2/coderd/healthcheck/health"
1615
"github.com/coder/coder/v2/codersdk/healthsdk"
16+
"github.com/coder/websocket"
1717
)
1818

1919
type WebsocketReport healthsdk.WebsocketReport

coderd/httpapi/httpapi.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ const websocketCloseMaxLen = 123
268268
func WebsocketCloseSprintf(format string, vars ...any) string {
269269
msg := fmt.Sprintf(format, vars...)
270270

271-
// Cap msg length at 123 bytes. nhooyr/websocket only allows close messages
271+
// Cap msg length at 123 bytes. coder/websocket only allows close messages
272272
// of this length.
273273
if len(msg) > websocketCloseMaxLen {
274274
// Trim the string to 123 bytes. If we accidentally cut in the middle of

coderd/httpapi/websocket.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import (
66
"time"
77

88
"golang.org/x/xerrors"
9-
"nhooyr.io/websocket"
109

1110
"cdr.dev/slog"
11+
"github.com/coder/websocket"
1212
)
1313

1414
// Heartbeat loops to ping a WebSocket to keep it alive.

coderd/provisionerjobs.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,17 @@ import (
1212

1313
"github.com/google/uuid"
1414
"golang.org/x/xerrors"
15-
"nhooyr.io/websocket"
1615

1716
"cdr.dev/slog"
18-
"github.com/coder/coder/v2/codersdk/wsjson"
19-
2017
"github.com/coder/coder/v2/coderd/database"
2118
"github.com/coder/coder/v2/coderd/database/db2sdk"
2219
"github.com/coder/coder/v2/coderd/database/dbauthz"
2320
"github.com/coder/coder/v2/coderd/database/pubsub"
2421
"github.com/coder/coder/v2/coderd/httpapi"
2522
"github.com/coder/coder/v2/codersdk"
23+
"github.com/coder/coder/v2/codersdk/wsjson"
2624
"github.com/coder/coder/v2/provisionersdk"
25+
"github.com/coder/websocket"
2726
)
2827

2928
// Returns provisioner logs based on query parameters.

coderd/provisionerjobs_internal_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414
"github.com/stretchr/testify/assert"
1515
"github.com/stretchr/testify/require"
1616
"go.uber.org/mock/gomock"
17-
"nhooyr.io/websocket"
1817

1918
"github.com/coder/coder/v2/coderd/database"
2019
"github.com/coder/coder/v2/coderd/database/dbmock"
@@ -23,6 +22,7 @@ import (
2322
"github.com/coder/coder/v2/codersdk"
2423
"github.com/coder/coder/v2/provisionersdk"
2524
"github.com/coder/coder/v2/testutil"
25+
"github.com/coder/websocket"
2626
)
2727

2828
func TestConvertProvisionerJob_Unit(t *testing.T) {

coderd/workspaceagents.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"golang.org/x/exp/slices"
2121
"golang.org/x/sync/errgroup"
2222
"golang.org/x/xerrors"
23-
"nhooyr.io/websocket"
2423
"tailscale.com/tailcfg"
2524

2625
"cdr.dev/slog"
@@ -42,6 +41,7 @@ import (
4241
"github.com/coder/coder/v2/codersdk/wsjson"
4342
"github.com/coder/coder/v2/tailnet"
4443
"github.com/coder/coder/v2/tailnet/proto"
44+
"github.com/coder/websocket"
4545
)
4646

4747
// @Summary Get workspace agent by ID
@@ -378,7 +378,7 @@ func (api *API) workspaceAgentLogs(rw http.ResponseWriter, r *http.Request) {
378378

379379
// Allow client to request no compression. This is useful for buggy
380380
// clients or if there's a client/server incompatibility. This is
381-
// needed with e.g. nhooyr/websocket and Safari (confirmed in 16.5).
381+
// needed with e.g. coder/websocket and Safari (confirmed in 16.5).
382382
//
383383
// See:
384384
// * https://github.com/nhooyr/websocket/issues/218

coderd/workspaceagents_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"github.com/stretchr/testify/require"
2121
"golang.org/x/xerrors"
2222
"google.golang.org/protobuf/types/known/timestamppb"
23-
"nhooyr.io/websocket"
2423
"tailscale.com/tailcfg"
2524

2625
"cdr.dev/slog"
@@ -50,6 +49,7 @@ import (
5049
"github.com/coder/coder/v2/tailnet/tailnettest"
5150
"github.com/coder/coder/v2/testutil"
5251
"github.com/coder/quartz"
52+
"github.com/coder/websocket"
5353
)
5454

5555
func TestWorkspaceAgent(t *testing.T) {

coderd/workspaceagentsrpc.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414
"github.com/google/uuid"
1515
"github.com/hashicorp/yamux"
1616
"golang.org/x/xerrors"
17-
"nhooyr.io/websocket"
1817

1918
"cdr.dev/slog"
2019
"github.com/coder/coder/v2/agent/proto"
@@ -30,6 +29,7 @@ import (
3029
"github.com/coder/coder/v2/codersdk"
3130
"github.com/coder/coder/v2/tailnet"
3231
tailnetproto "github.com/coder/coder/v2/tailnet/proto"
32+
"github.com/coder/websocket"
3333
)
3434

3535
// @Summary Workspace agent RPC API

coderd/workspaceagentsrpc_internal_test.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,17 @@ import (
88
"testing"
99
"time"
1010

11-
"github.com/coder/coder/v2/coderd/util/ptr"
12-
"github.com/coder/coder/v2/coderd/wspubsub"
13-
1411
"github.com/google/uuid"
1512
"github.com/stretchr/testify/require"
1613
"go.uber.org/mock/gomock"
17-
"nhooyr.io/websocket"
1814

1915
"github.com/coder/coder/v2/coderd/database"
2016
"github.com/coder/coder/v2/coderd/database/dbmock"
2117
"github.com/coder/coder/v2/coderd/database/dbtime"
18+
"github.com/coder/coder/v2/coderd/util/ptr"
19+
"github.com/coder/coder/v2/coderd/wspubsub"
2220
"github.com/coder/coder/v2/testutil"
21+
"github.com/coder/websocket"
2322
)
2423

2524
func TestAgentConnectionMonitor_ContextCancel(t *testing.T) {

coderd/workspaceapps/proxy.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import (
1717
"github.com/go-jose/go-jose/v4/jwt"
1818
"github.com/google/uuid"
1919
"go.opentelemetry.io/otel/trace"
20-
"nhooyr.io/websocket"
2120

2221
"cdr.dev/slog"
2322
"github.com/coder/coder/v2/agent/agentssh"
@@ -32,6 +31,7 @@ import (
3231
"github.com/coder/coder/v2/codersdk"
3332
"github.com/coder/coder/v2/codersdk/workspacesdk"
3433
"github.com/coder/coder/v2/site"
34+
"github.com/coder/websocket"
3535
)
3636

3737
const (

codersdk/agentsdk/agentsdk.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import (
1515
"github.com/google/uuid"
1616
"github.com/hashicorp/yamux"
1717
"golang.org/x/xerrors"
18-
"nhooyr.io/websocket"
1918
"storj.io/drpc"
2019
"tailscale.com/tailcfg"
2120

@@ -25,6 +24,7 @@ import (
2524
"github.com/coder/coder/v2/codersdk"
2625
drpcsdk "github.com/coder/coder/v2/codersdk/drpc"
2726
tailnetproto "github.com/coder/coder/v2/tailnet/proto"
27+
"github.com/coder/websocket"
2828
)
2929

3030
// ExternalLogSourceID is the statically-defined ID of a log-source that

codersdk/provisionerdaemons.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ import (
1515
"golang.org/x/exp/maps"
1616
"golang.org/x/exp/slices"
1717
"golang.org/x/xerrors"
18-
"nhooyr.io/websocket"
1918

2019
"github.com/coder/coder/v2/buildinfo"
2120
"github.com/coder/coder/v2/codersdk/drpc"
2221
"github.com/coder/coder/v2/codersdk/wsjson"
2322
"github.com/coder/coder/v2/provisionerd/proto"
2423
"github.com/coder/coder/v2/provisionerd/runner"
24+
"github.com/coder/websocket"
2525
)
2626

2727
type LogSource string

codersdk/websocket.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"context"
55
"net"
66

7-
"nhooyr.io/websocket"
7+
"github.com/coder/websocket"
88
)
99

1010
// wsNetConn wraps net.Conn created by websocket.NetConn(). Cancel func

codersdk/websocket_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ import (
88

99
"github.com/stretchr/testify/assert"
1010
"github.com/stretchr/testify/require"
11-
"nhooyr.io/websocket"
1211

1312
"github.com/coder/coder/v2/codersdk"
1413
"github.com/coder/coder/v2/testutil"
14+
"github.com/coder/websocket"
1515
)
1616

1717
// TestWebsocketNetConn_LargeWrites tests that we can write large amounts of data thru the netconn

codersdk/workspaceagents.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ import (
1212

1313
"github.com/google/uuid"
1414
"golang.org/x/xerrors"
15-
"nhooyr.io/websocket"
1615

1716
"github.com/coder/coder/v2/coderd/tracing"
1817
"github.com/coder/coder/v2/codersdk/wsjson"
18+
"github.com/coder/websocket"
1919
)
2020

2121
type WorkspaceAgentStatus string

codersdk/workspacesdk/dialer.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ import (
99
"slices"
1010

1111
"golang.org/x/xerrors"
12-
"nhooyr.io/websocket"
1312

1413
"cdr.dev/slog"
1514
"github.com/coder/coder/v2/buildinfo"
1615
"github.com/coder/coder/v2/codersdk"
1716
"github.com/coder/coder/v2/tailnet"
1817
"github.com/coder/coder/v2/tailnet/proto"
18+
"github.com/coder/websocket"
1919
)
2020

2121
var permanentErrorStatuses = []int{

codersdk/workspacesdk/dialer_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
"github.com/stretchr/testify/assert"
1414
"github.com/stretchr/testify/require"
1515
"go.uber.org/mock/gomock"
16-
"nhooyr.io/websocket"
1716
"tailscale.com/tailcfg"
1817

1918
"cdr.dev/slog"
@@ -26,6 +25,7 @@ import (
2625
tailnetproto "github.com/coder/coder/v2/tailnet/proto"
2726
"github.com/coder/coder/v2/tailnet/tailnettest"
2827
"github.com/coder/coder/v2/testutil"
28+
"github.com/coder/websocket"
2929
)
3030

3131
func TestWebsocketDialer_TokenController(t *testing.T) {

codersdk/workspacesdk/workspacesdk.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414

1515
"github.com/google/uuid"
1616
"golang.org/x/xerrors"
17-
"nhooyr.io/websocket"
1817
"tailscale.com/tailcfg"
1918
"tailscale.com/wgengine/capture"
2019

@@ -23,6 +22,7 @@ import (
2322
"github.com/coder/coder/v2/tailnet"
2423
"github.com/coder/coder/v2/tailnet/proto"
2524
"github.com/coder/quartz"
25+
"github.com/coder/websocket"
2626
)
2727

2828
var ErrSkipClose = xerrors.New("skip tailnet close")

codersdk/wsjson/decoder.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@ import (
55
"encoding/json"
66
"sync/atomic"
77

8-
"nhooyr.io/websocket"
9-
108
"cdr.dev/slog"
9+
"github.com/coder/websocket"
1110
)
1211

1312
type Decoder[T any] struct {

codersdk/wsjson/encoder.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import (
55
"encoding/json"
66

77
"golang.org/x/xerrors"
8-
"nhooyr.io/websocket"
8+
9+
"github.com/coder/websocket"
910
)
1011

1112
type Encoder[T any] struct {

enterprise/coderd/provisionerdaemons.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,10 @@ import (
1515
"go.opentelemetry.io/otel/trace"
1616
"golang.org/x/exp/maps"
1717
"golang.org/x/xerrors"
18-
"nhooyr.io/websocket"
1918
"storj.io/drpc/drpcmux"
2019
"storj.io/drpc/drpcserver"
2120

2221
"cdr.dev/slog"
23-
2422
"github.com/coder/coder/v2/coderd/database"
2523
"github.com/coder/coder/v2/coderd/database/db2sdk"
2624
"github.com/coder/coder/v2/coderd/database/dbauthz"
@@ -35,6 +33,7 @@ import (
3533
"github.com/coder/coder/v2/codersdk"
3634
"github.com/coder/coder/v2/provisionerd/proto"
3735
"github.com/coder/coder/v2/provisionersdk"
36+
"github.com/coder/websocket"
3837
)
3938

4039
func (api *API) provisionerDaemonsEnabledMW(next http.Handler) http.Handler {

enterprise/coderd/workspaceproxycoordinate.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ import (
44
"net/http"
55

66
"github.com/google/uuid"
7-
"nhooyr.io/websocket"
87

98
"github.com/coder/coder/v2/apiversion"
109
"github.com/coder/coder/v2/coderd/httpapi"
1110
"github.com/coder/coder/v2/codersdk"
1211
"github.com/coder/coder/v2/tailnet/proto"
12+
"github.com/coder/websocket"
1313
)
1414

1515
// @Summary Workspace Proxy Coordinate

enterprise/wsproxy/wsproxysdk/wsproxysdk.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010

1111
"github.com/google/uuid"
1212
"golang.org/x/xerrors"
13-
"nhooyr.io/websocket"
1413
"tailscale.com/tailcfg"
1514

1615
"cdr.dev/slog"
@@ -19,6 +18,7 @@ import (
1918
"github.com/coder/coder/v2/codersdk"
2019
"github.com/coder/coder/v2/codersdk/workspacesdk"
2120
agpl "github.com/coder/coder/v2/tailnet"
21+
"github.com/coder/websocket"
2222
)
2323

2424
// Client is a HTTP client for a subset of Coder API routes that external

go.mod

+3-3
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ replace github.com/dlclark/regexp2 => github.com/dlclark/regexp2 v1.7.0
3939

4040
// There are a few minor changes we make to Tailscale that we're slowly upstreaming. Compare here:
4141
// https://github.com/tailscale/tailscale/compare/main...coder:tailscale:main
42-
replace tailscale.com => github.com/coder/tailscale v1.1.1-0.20241003034647-02286e537fc2
42+
replace tailscale.com => github.com/coder/tailscale v1.1.1-0.20241218201526-b53d914d625f
4343

4444
// This is replaced to include
4545
// 1. a fix for a data race: c.f. https://github.com/tailscale/wireguard-go/pull/25
@@ -177,7 +177,7 @@ require (
177177
golang.org/x/crypto v0.31.0
178178
golang.org/x/exp v0.0.0-20240808152545-0cdaa3abc0fa
179179
golang.org/x/mod v0.22.0
180-
golang.org/x/net v0.31.0
180+
golang.org/x/net v0.32.0
181181
golang.org/x/oauth2 v0.24.0
182182
golang.org/x/sync v0.10.0
183183
golang.org/x/sys v0.28.0
@@ -192,7 +192,6 @@ require (
192192
gopkg.in/natefinch/lumberjack.v2 v2.2.1
193193
gopkg.in/yaml.v3 v3.0.1
194194
gvisor.dev/gvisor v0.0.0-20240509041132-65b30f7869dc
195-
nhooyr.io/websocket v1.8.7
196195
storj.io/drpc v0.0.33
197196
tailscale.com v1.46.1
198197
)
@@ -205,6 +204,7 @@ require (
205204
github.com/charmbracelet/bubbletea v1.2.1
206205
github.com/charmbracelet/lipgloss v1.0.0
207206
github.com/coder/serpent v0.10.0
207+
github.com/coder/websocket v1.8.12
208208
github.com/emersion/go-sasl v0.0.0-20200509203442-7bfe0ed36a21
209209
github.com/emersion/go-smtp v0.21.2
210210
github.com/go-jose/go-jose/v4 v4.0.2

0 commit comments

Comments
 (0)