{"record":{"id":"2f37bd5e2a272004","repo":"hashicorp/terraform","slug":"timeout-last-error-v","errorCode":null,"errorMessage":"timeout - last error: %v","messagePattern":"timeout - last error: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/communicator/communicator.go","lineNumber":166,"sourceCode":"\n\t// Wait for completion\n\tselect {\n\tcase <-ctx.Done():\n\tcase <-doneCh:\n\t}\n\n\tvar lastErr error\n\t// Check if we got an error executing\n\tif ev, ok := errVal.Load().(errWrap); ok {\n\t\tlastErr = ev.E\n\t}\n\n\t// Check if we have a context error to check if we're interrupted or timeout\n\tswitch ctx.Err() {\n\tcase context.Canceled:\n\t\treturn fmt.Errorf(\"interrupted - last error: %v\", lastErr)\n\tcase context.DeadlineExceeded:\n\t\treturn fmt.Errorf(\"timeout - last error: %v\", lastErr)\n\t}\n\n\tif lastErr != nil {\n\t\treturn lastErr\n\t}\n\treturn nil\n}\n","sourceCodeStart":148,"sourceCodeEnd":174,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/communicator/communicator.go#L148-L174","documentation":"Same Retry loop as 777, but the context hit its deadline (context.DeadlineExceeded) at communicator.go:165. The last retryable error is included so you can see why retries kept failing. This is governed by the provisioner/connection timeout.","triggerScenarios":"The retry context deadline elapses before f succeeds — the provisioner 'timeout' argument or the command timeout was exceeded while the remote op kept failing.","commonSituations":"Slow or unreachable remote host; flaky network; long-running remote command exceeding the configured timeout; sshd slow to start on a freshly-booted instance.","solutions":["Raise the 'timeout' in the connection block (e.g. timeout = \"10m\").","Verify host reachability, open ports, and firewall/security-group rules.","Address the appended 'last error' (auth, network, DNS) so retries succeed before the deadline."],"exampleFix":"// before\nconnection {\n  type    = \"ssh\"\n  user    = \"ubuntu\"\n  host    = aws_instance.web.public_ip\n  timeout = \"30s\"\n}\nError: timeout - last error: dial tcp ...: i/o timeout\n\n// after\nconnection {\n  type    = \"ssh\"\n  user    = \"ubuntu\"\n  host    = aws_instance.web.public_ip\n  timeout = \"10m\"\n}","handlingStrategy":"try-catch","validationCode":"// Size the timeout to the worst-case remote op, not the happy path.\ntimeout := 5 * time.Minute // raise as needed for slow hosts\nctx, cancel := context.WithTimeout(parentCtx, timeout)\ndefer cancel()","typeGuard":"null","tryCatchPattern":"err := communicator.Retry(ctx, func() error { return c.Connect(o) })\nif err != nil && errors.Is(ctx.Err(), context.DeadlineExceeded) {\n    // distinguish 'timeout' from a hard auth failure and guide the user\n}","preventionTips":["Set a generous connection/command timeout for slow or ephemeral hosts.","Pre-flight check host reachability (port open, security groups) before provisioning.","Address the underlying retryable error so retries succeed before the deadline."],"tags":["terraform","provisioner","retry","timeout","context"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T20:17:04.800Z"}