{"record":{"id":"726e916866fcef04","repo":"wavetermdev/waveterm","slug":"cancelled-while-waiting-for-app-port-w","errorCode":null,"errorMessage":"cancelled while waiting for app port: %w","messagePattern":"cancelled while waiting for app port: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"pkg/buildercontroller/buildercontroller.go","lineNumber":411,"sourceCode":"\t\t}\n\t}()\n\n\ttimeout := time.NewTimer(5 * time.Second)\n\tdefer timeout.Stop()\n\n\tselect {\n\tcase port := <-portChan:\n\t\tprocess.Port = port\n\t\treturn process, nil\n\tcase err := <-errChan:\n\t\tcmd.Process.Kill()\n\t\treturn nil, err\n\tcase <-timeout.C:\n\t\tcmd.Process.Kill()\n\t\treturn nil, fmt.Errorf(\"timeout waiting for port\")\n\tcase <-ctx.Done():\n\t\tcmd.Process.Kill()\n\t\treturn nil, fmt.Errorf(\"cancelled while waiting for app port: %w\", ctx.Err())\n\t}\n}\n\nfunc (bc *BuilderController) handleBuildError(err error, resultCh chan<- *BuildResult) {\n\tbc.lock.Lock()\n\tdefer bc.lock.Unlock()\n\tbc.setStatus_nolock(BuilderStatus_Error, 0, 1, err.Error())\n\n\tif resultCh != nil {\n\t\tbuildOutput := \"\"\n\t\tif bc.outputBuffer != nil {\n\t\t\tlines := bc.outputBuffer.GetLines()\n\t\t\tbuildOutput = strings.Join(lines, \"\\n\")\n\t\t}\n\t\tselect {\n\t\tcase resultCh <- &BuildResult{\n\t\t\tSuccess:      false,\n\t\t\tErrorMessage: err.Error(),","sourceCodeStart":393,"sourceCodeEnd":429,"githubUrl":"https://github.com/wavetermdev/waveterm/blob/a4447c1563b2df285ab89e76c82f91e1a1a49c1e/pkg/buildercontroller/buildercontroller.go#L393-L429","documentation":"While waiting for the builder app's port, runBuilderApp also watches the caller's context. If the context is cancelled (user cancelled the build, block closed, app shutdown), the subprocess is killed and this error wraps ctx.Err() (context.Canceled or context.DeadlineExceeded).","triggerScenarios":"ctx.Done() fires during the 5-second port wait — caller cancellation, block teardown, or a context deadline set by an ancestor expiring.","commonSituations":"User closes the terminal block or cancels the run while the builder app is starting; Wave shutdown cancels in-flight builds; upstream deadline shorter than the 5s port wait.","solutions":["Confirm the cancellation was intentional (block closed / user cancel); if so, no action needed","If unintended, check ancestor context deadlines that expire during startup","Retry the build with a fresh context if the cancellation was accidental"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"process, err := bc.runBuilderApp(ctx, ...)\nif err != nil {\n    if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) {\n        return nil // expected on cancel/shutdown; clean up quietly\n    }\n    return err\n}","preventionTips":["Pass a context whose lifetime covers the full build+startup window","Avoid ancestor contexts with deadlines shorter than the 5s port wait","Treat cancellation as normal flow when closing blocks or shutting down","Use errors.Is on the wrapped ctx.Err() to distinguish cancel vs deadline"],"tags":["context","cancellation","subprocess","go"],"backgroundTag":"context-cancelled","analyzedSha":"a4447c1563b2df285ab89e76c82f91e1a1a49c1e","analyzedAt":"2026-09-01T15:26:23.972Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}