Skip to content

Commit 151aaad

Browse files
authored
fix: allow startup scripts larger than 32k (#12060)
Fixes #12057 and adds a regression test.
1 parent 4d63a47 commit 151aaad

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

coderd/workspaceagentsrpc_test.go

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package coderd_test
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/require"
7+
8+
agentproto "github.com/coder/coder/v2/agent/proto"
9+
"github.com/coder/coder/v2/coderd/coderdtest"
10+
"github.com/coder/coder/v2/coderd/database"
11+
"github.com/coder/coder/v2/coderd/database/dbfake"
12+
"github.com/coder/coder/v2/codersdk/agentsdk"
13+
"github.com/coder/coder/v2/provisionersdk/proto"
14+
"github.com/coder/coder/v2/testutil"
15+
)
16+
17+
func TestAgentAPI_LargeManifest(t *testing.T) {
18+
t.Parallel()
19+
ctx := testutil.Context(t, testutil.WaitLong)
20+
client, store := coderdtest.NewWithDatabase(t, nil)
21+
adminUser := coderdtest.CreateFirstUser(t, client)
22+
n := 512000
23+
longScript := make([]byte, n)
24+
for i := range longScript {
25+
longScript[i] = 'q'
26+
}
27+
r := dbfake.WorkspaceBuild(t, store, database.Workspace{
28+
OrganizationID: adminUser.OrganizationID,
29+
OwnerID: adminUser.UserID,
30+
}).WithAgent(func(agents []*proto.Agent) []*proto.Agent {
31+
agents[0].Scripts = []*proto.Script{
32+
{
33+
Script: string(longScript),
34+
},
35+
}
36+
return agents
37+
}).Do()
38+
ac := agentsdk.New(client.URL)
39+
ac.SetSessionToken(r.AgentToken)
40+
conn, err := ac.ConnectRPC(ctx)
41+
defer func() {
42+
_ = conn.Close()
43+
}()
44+
require.NoError(t, err)
45+
agentAPI := agentproto.NewDRPCAgentClient(conn)
46+
manifest, err := agentAPI.GetManifest(ctx, &agentproto.GetManifestRequest{})
47+
require.NoError(t, err)
48+
require.Len(t, manifest.Scripts, 1)
49+
require.Len(t, manifest.Scripts[0].Script, n)
50+
}

codersdk/agentsdk/agentsdk.go

+3
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,9 @@ func (c *wsNetConn) Close() error {
629629
// during read or write will cancel the context, but not close the
630630
// conn. Close should be called to release context resources.
631631
func websocketNetConn(ctx context.Context, conn *websocket.Conn, msgType websocket.MessageType) (context.Context, net.Conn) {
632+
// Set the read limit to 4 MiB -- about the limit for protobufs. This needs to be larger than
633+
// the default because some of our protocols can include large messages like startup scripts.
634+
conn.SetReadLimit(1 << 22)
632635
ctx, cancel := context.WithCancel(ctx)
633636
nc := websocket.NetConn(ctx, conn, msgType)
634637
return ctx, &wsNetConn{

0 commit comments

Comments
 (0)