{"record":{"id":"ed5978ec3d043dc9","repo":"wavetermdev/waveterm","slug":"failed-to-set-rwnd-size-w","errorCode":null,"errorMessage":"failed to set rwnd size: %w","messagePattern":"failed to set rwnd size: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/jobmanager/jobmanager.go","lineNumber":371,"sourceCode":"func (jm *JobManager) StartStream(msc *MainServerConn) error {\n\tjm.lock.Lock()\n\tdefer jm.lock.Unlock()\n\n\tif jm.Cmd == nil {\n\t\treturn fmt.Errorf(\"job not started\")\n\t}\n\tif jm.pendingStreamMeta == nil {\n\t\treturn fmt.Errorf(\"no pending stream (call PrepareConnect first)\")\n\t}\n\n\terr := msc.WshRpc.StreamBroker.AttachStreamWriter(jm.pendingStreamMeta, jm.StreamManager)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to attach stream writer: %w\", err)\n\t}\n\n\terr = jm.StreamManager.SetRwndSize(int(jm.pendingStreamMeta.RWnd))\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to set rwnd size: %w\", err)\n\t}\n\n\tlog.Printf(\"StartStream: streamid=%s rwnd=%d streaming started\\n\", jm.pendingStreamMeta.Id, jm.pendingStreamMeta.RWnd)\n\tjm.pendingStreamMeta = nil\n\treturn nil\n}\n\nfunc MakeJobDomainSocket(clientId string, jobId string) error {\n\tsocketDir := filepath.Join(\"/tmp\", fmt.Sprintf(\"waveterm-%d\", os.Getuid()))\n\terr := os.MkdirAll(socketDir, 0700)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to create socket directory: %w\", err)\n\t}\n\n\tsocketPath := wavebase.GetRemoteJobSocketPath(jobId)\n\n\tos.Remove(socketPath)\n","sourceCodeStart":353,"sourceCodeEnd":389,"githubUrl":"https://github.com/wavetermdev/waveterm/blob/a4447c1563b2df285ab89e76c82f91e1a1a49c1e/pkg/jobmanager/jobmanager.go#L353-L389","documentation":"After a successful attach, StartStream applies the receiver-window size negotiated in pendingStreamMeta via StreamManager.SetRwndSize. This error wraps any failure from that call. It indicates the stream is attached but flow-control configuration could not be applied, so the stream is left partially initialized.","triggerScenarios":"SetRwndSize returns an error — typically an invalid, zero, or out-of-range RWnd value in pendingStreamMeta, or the StreamManager rejecting the resize for an attached/invalid stream state.","commonSituations":"Peer negotiated a bad RWnd value during PrepareConnect; integer overflow/widening issue in int(jm.pendingStreamMeta.RWnd); StreamManager not fully initialized before StartStream; version skew where window-size semantics changed.","solutions":["Log jm.pendingStreamMeta.RWnd and the wrapped error to see whether the negotiated value is sane","Validate RWnd is > 0 (and within protocol bounds) before calling StartStream; re-run PrepareConnect if not","Re-do the PrepareConnect/StartStream cycle to renegotiate a fresh window size","Check StreamManager initialization order so SetRwndSize runs on a ready stream"],"exampleFix":"// before\njm.StartStream() // trusts pendingStreamMeta.RWnd\n// after\nif jm.pendingStreamMeta == nil || jm.pendingStreamMeta.RWnd == 0 {\n    return fmt.Errorf(\"invalid rwnd negotiated, re-run PrepareConnect\")\n}\nif err := jm.StartStream(); err != nil {\n    return err\n}","handlingStrategy":"validation","validationCode":"if jm.pendingStreamMeta == nil || jm.pendingStreamMeta.RWnd == 0 {\n    return fmt.Errorf(\"invalid stream metadata/rwnd, re-run PrepareConnect\")\n}","typeGuard":"func validPendingStream(jm *JobManager) bool {\n    return jm.pendingStreamMeta != nil && jm.pendingStreamMeta.RWnd > 0\n}","tryCatchPattern":"if err := jm.StartStream(); err != nil {\n    if strings.HasPrefix(err.Error(), \"failed to set rwnd size\") {\n        log.Printf(\"rwnd error: %v\", errors.Unwrap(err))\n        // renegotiate and retry\n        if perr := jm.PrepareConnect(); perr == nil {\n            err = jm.StartStream()\n        }\n    }\n    return err\n}","preventionTips":["Validate the negotiated RWnd value before starting the stream","Re-run the PrepareConnect/StartStream pair on any partial-initialization error","Check StreamManager initialization order in setup code","Watch for platform int-width issues when converting RWnd"],"tags":["go","streaming","flow-control","wrapped-error"],"backgroundTag":"rwnd-set-failed","analyzedSha":"a4447c1563b2df285ab89e76c82f91e1a1a49c1e","analyzedAt":"2026-09-01T15:26:23.972Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}