{"record":{"id":"bf7a2674994574f1","repo":"wavetermdev/waveterm","slug":"context-timeout-bf7a26","errorCode":null,"errorMessage":"context timeout","messagePattern":"context timeout","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"pkg/wslconn/wslconn.go","lineNumber":475,"sourceCode":"\nfunc (conn *WslConn) Reconnect(ctx context.Context) error {\n\terr := conn.Close()\n\tif err != nil {\n\t\treturn err\n\t}\n\treturn conn.Connect(ctx)\n}\n\nfunc (conn *WslConn) WaitForConnect(ctx context.Context) error {\n\tfor {\n\t\tstatus := conn.DeriveConnStatus()\n\t\tif status.Status == Status_Connected {\n\t\t\treturn nil\n\t\t}\n\t\tif status.Status == Status_Connecting {\n\t\t\tselect {\n\t\t\tcase <-ctx.Done():\n\t\t\t\treturn fmt.Errorf(\"context timeout\")\n\t\t\tcase <-time.After(100 * time.Millisecond):\n\t\t\t\tcontinue\n\t\t\t}\n\t\t}\n\t\tif status.Status == Status_Init || status.Status == Status_Disconnected {\n\t\t\treturn fmt.Errorf(\"disconnected\")\n\t\t}\n\t\tif status.Status == Status_Error {\n\t\t\treturn fmt.Errorf(\"error: %v\", status.Error)\n\t\t}\n\t\treturn fmt.Errorf(\"unknown status: %q\", status.Status)\n\t}\n}\n\n// does not return an error since that error is stored inside of WslConn\nfunc (conn *WslConn) Connect(ctx context.Context) error {\n\tvar connectAllowed bool\n\tconn.WithLock(func() {","sourceCodeStart":457,"sourceCodeEnd":493,"githubUrl":"https://github.com/wavetermdev/waveterm/blob/a4447c1563b2df285ab89e76c82f91e1a1a49c1e/pkg/wslconn/wslconn.go#L457-L493","documentation":"WaitForConnect polls DeriveConnStatus every 100ms and returns this error when the caller-supplied context is canceled or its deadline expires while the connection is still in Status_Connecting. It signals 'gave up waiting' — the connection may still complete later, but this waiter stopped waiting.","triggerScenarios":"Calling WaitForConnect with a context whose deadline is shorter than the time the WSL connection takes to establish, or canceling the context (user cancel / shutdown) mid-connect.","commonSituations":"Short timeouts (e.g. a few seconds) on slow machine or cold WSL startup; user cancels a connecting block; app shutdown cancels contexts while connections are still in progress.","solutions":["Increase the context deadline passed to WaitForConnect (WSL cold start can take many seconds)","Check final connection state after the timeout — the connection may have succeeded after you stopped waiting","If cancellation was intentional, treat this as a normal cancellation and clean up rather than retrying","Retry with a fresh context if the connect should be given another chance"],"exampleFix":"// before\nctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)\n// after\nctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)\nerr := conn.WaitForConnect(ctx)","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)\ndefer cancel()\nif err := conn.WaitForConnect(ctx); err != nil {\n    if err.Error() == \"context timeout\" {\n        // check final state: connection may have completed after we gave up\n        if conn.DeriveConnStatus().Status == Status_Connected {\n            err = nil\n        }\n    }\n}","preventionTips":["Use generous deadlines — WSL cold start can exceed 10s","After a timeout, re-check DeriveConnStatus before declaring failure","Distinguish user cancellation (no retry) from deadline expiry (retry)"],"tags":["wsl","timeout","context","connection"],"backgroundTag":"context-deadline-exceeded","analyzedSha":"a4447c1563b2df285ab89e76c82f91e1a1a49c1e","analyzedAt":"2026-09-01T15:26:23.972Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}