fix(ws): raise bounded agent message limit
CI / Test (store) (pull_request) Successful in 6s
CI / Lint (pull_request) Failing after 20s
CI / Build (windows/amd64) (pull_request) Successful in 8s
CI / Test (rest) (pull_request) Successful in 38s
CI / Build (linux/amd64) (pull_request) Successful in 7s
CI / Build (linux/arm64) (pull_request) Successful in 8s
CI / Test (server-http) (pull_request) Successful in 1m28s
e2e / Playwright vs docker-compose (pull_request) Successful in 1m24s
CI / Test (store) (pull_request) Successful in 6s
CI / Lint (pull_request) Failing after 20s
CI / Build (windows/amd64) (pull_request) Successful in 8s
CI / Test (rest) (pull_request) Successful in 38s
CI / Build (linux/amd64) (pull_request) Successful in 7s
CI / Build (linux/arm64) (pull_request) Successful in 8s
CI / Test (server-http) (pull_request) Successful in 1m28s
e2e / Playwright vs docker-compose (pull_request) Successful in 1m24s
This commit is contained in:
@@ -77,6 +77,7 @@ func AgentHandler(deps HandlerDeps) stdhttp.Handler {
|
||||
slog.Warn("ws accept failed", "err", err, "host_id", host.ID)
|
||||
return
|
||||
}
|
||||
conn.SetReadLimit(api.MaxWebSocketMessageBytes)
|
||||
|
||||
c := NewConn(host.ID, conn)
|
||||
// Keep agents alive across NAT boxes; coder/websocket
|
||||
|
||||
@@ -123,6 +123,68 @@ func TestWSHelloAndHeartbeat(t *testing.T) {
|
||||
t.Error("heartbeat did not update last_seen_at")
|
||||
}
|
||||
|
||||
func TestWSAcceptsSnapshotReportLargerThanDefaultReadLimit(t *testing.T) {
|
||||
t.Parallel()
|
||||
url, token, hostID, st, hub := setupTestHub(t)
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer cancel()
|
||||
c, _, err := websocket.Dial(ctx, url, &websocket.DialOptions{
|
||||
HTTPHeader: stdhttp.Header{"Authorization": []string{"Bearer " + token}},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("dial: %v", err)
|
||||
}
|
||||
defer c.CloseNow() //nolint:errcheck
|
||||
|
||||
hello, _ := api.Marshal(api.MsgHello, "", api.HelloPayload{
|
||||
ProtocolVersion: api.CurrentProtocolVersion,
|
||||
AgentVersion: "0.1.0",
|
||||
ResticVersion: "0.17.1",
|
||||
Hostname: "h1",
|
||||
OS: api.OSLinux,
|
||||
Arch: api.ArchAmd64,
|
||||
})
|
||||
helloRaw, _ := json.Marshal(hello)
|
||||
if err := c.Write(ctx, websocket.MessageText, helloRaw); err != nil {
|
||||
t.Fatalf("write hello: %v", err)
|
||||
}
|
||||
deadline := time.Now().Add(time.Second)
|
||||
for !hub.Connected(hostID) && time.Now().Before(deadline) {
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
}
|
||||
|
||||
report, _ := api.Marshal(api.MsgSnapshotsRpt, "", api.SnapshotsReportPayload{
|
||||
Snapshots: []api.Snapshot{{
|
||||
ID: strings.Repeat("a", 64),
|
||||
ShortID: "aaaaaaaa",
|
||||
Time: time.Now().UTC(),
|
||||
Hostname: "h1",
|
||||
Paths: []string{"/" + strings.Repeat("long-path/", 5000)},
|
||||
}},
|
||||
})
|
||||
reportRaw, _ := json.Marshal(report)
|
||||
if len(reportRaw) <= 32*1024 {
|
||||
t.Fatalf("test payload is only %d bytes; must exceed old limit", len(reportRaw))
|
||||
}
|
||||
if int64(len(reportRaw)) >= api.MaxWebSocketMessageBytes {
|
||||
t.Fatalf("test payload %d exceeds protocol limit", len(reportRaw))
|
||||
}
|
||||
if err := c.Write(ctx, websocket.MessageText, reportRaw); err != nil {
|
||||
t.Fatalf("write snapshots.report: %v", err)
|
||||
}
|
||||
|
||||
deadline = time.Now().Add(2 * time.Second)
|
||||
for time.Now().Before(deadline) {
|
||||
host, err := st.GetHost(context.Background(), hostID)
|
||||
if err == nil && host.SnapshotCount == 1 {
|
||||
return
|
||||
}
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
}
|
||||
t.Fatal("oversized snapshots.report was not projected")
|
||||
}
|
||||
|
||||
func TestWSRejectsOldProtocol(t *testing.T) {
|
||||
t.Parallel()
|
||||
url, token, _, _, _ := setupTestHub(t)
|
||||
|
||||
Reference in New Issue
Block a user