{"record":{"id":"0fef894f05a82e94","repo":"hashicorp/terraform","slug":"canceled-reading-current-outputs","errorCode":null,"errorMessage":"canceled reading current outputs","messagePattern":"canceled reading current outputs","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"internal/cloud/state.go","lineNumber":570,"sourceCode":"\terr := RetryBackoff(ctx, func() error {\n\t\tvar err error\n\t\tso, err = s.tfeClient.StateVersionOutputs.ReadCurrent(ctx, s.workspace.ID)\n\n\t\tif err != nil {\n\t\t\tif strings.Contains(err.Error(), \"service unavailable\") {\n\t\t\t\treturn err\n\t\t\t}\n\t\t\treturn NonRetryableError{err}\n\t\t}\n\t\treturn nil\n\t})\n\n\tif err != nil {\n\t\tswitch err {\n\t\tcase context.DeadlineExceeded:\n\t\t\treturn nil, fmt.Errorf(\"current outputs were not ready to be read within the deadline. Please try again\")\n\t\tcase context.Canceled:\n\t\t\treturn nil, fmt.Errorf(\"canceled reading current outputs\")\n\t\t}\n\t\treturn nil, fmt.Errorf(\"could not read state version outputs: %w\", err)\n\t}\n\n\tresult := make(map[string]*states.OutputValue)\n\n\tfor _, output := range so.Items {\n\t\tif output.DetailedType == nil {\n\t\t\t// If there is no detailed type information available, this state was probably created\n\t\t\t// with a version of terraform < 1.3.0. In this case, we'll eject completely from this\n\t\t\t// function and fall back to the old behavior of reading the entire state file, which\n\t\t\t// requires a higher level of authorization.\n\t\t\tlog.Printf(\"[DEBUG] falling back to reading full state\")\n\n\t\t\tif err := s.RefreshState(); err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"failed to load state: %w\", err)\n\t\t\t}\n","sourceCodeStart":552,"sourceCodeEnd":588,"githubUrl":"https://github.com/hashicorp/terraform/blob/d32a084675427f5ac3f7d2868578ef8b2c1dc525/internal/cloud/state.go#L552-L588","documentation":"Thrown by GetRootOutputValues when the caller-supplied context (not the internal 1-minute deadline) is canceled while RetryBackoff is retrying StateVersionOutputs.ReadCurrent. This is distinct from DeadlineExceeded: the parent context was explicitly canceled, typically because the user pressed Ctrl+C or the calling command was terminated.","triggerScenarios":"User cancels the terraform command (Ctrl+C / SIGINT) during output reading; parent process (CI runner, wrapper script) terminates and cancels the context; a programmatic caller cancels the context due to its own timeout or shutdown.","commonSituations":"User impatient during a slow output read and presses Ctrl+C; CI job cancelled by the orchestration system; terraform invoked as a subprocess and the parent process is killed.","solutions":["If intentional cancellation, no action needed — this is expected behavior","If unexpected, investigate why the parent context was canceled (upstream timeout, signal handling)","Avoid canceling terraform mid-operation if output consistency is needed; let operations complete"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Use a context that will not be prematurely canceled:\nctx := context.Background() // or a context with a generous deadline, not one tied to an interrupt\noutputs, err := state.GetRootOutputValues(ctx)","typeGuard":null,"tryCatchPattern":"outputs, err := state.GetRootOutputValues(ctx)\nif err != nil {\n    if errors.Is(ctx.Err(), context.Canceled) || strings.Contains(err.Error(), \"canceled reading\") {\n        // caller intentionally canceled — no retry needed\n        return nil, err\n    }\n    return nil, err\n}","preventionTips":["Do not bind the context for GetRootOutputValues to a SIGINT handler that cancels immediately","In CI, ensure the job timeout exceeds the expected output-read window","Let terraform complete output reading before terminating the process"],"tags":["outputs","context","cancellation","tfe","terraform"],"backgroundTag":null,"analyzedSha":"d32a084675427f5ac3f7d2868578ef8b2c1dc525","analyzedAt":"2026-08-11T18:43:52.779Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}