{"record":{"id":"86a7efbbead94280","repo":"go-delve/delve","slug":"waitfor-duration-expired","errorCode":null,"errorMessage":"waitfor duration expired","messagePattern":"waitfor duration expired","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/proc/native/proc.go","lineNumber":89,"sourceCode":"\t\tbi:           proc.NewBinaryInfo(runtime.GOOS, runtime.GOARCH),\n\t}\n}\n\n// WaitFor waits for a process as specified by waitFor.\nfunc WaitFor(waitFor *proc.WaitFor) (int, error) {\n\tt0 := time.Now()\n\tseen := make(map[int]struct{})\n\tfor (waitFor.Duration == 0) || (time.Since(t0) < waitFor.Duration) {\n\t\tpid, err := waitForSearchProcess(waitFor.Name, seen)\n\t\tif err != nil {\n\t\t\treturn 0, err\n\t\t}\n\t\tif pid != 0 {\n\t\t\treturn pid, nil\n\t\t}\n\t\ttime.Sleep(waitFor.Interval)\n\t}\n\treturn 0, errors.New(\"waitfor duration expired\")\n}\n\n// BinInfo will return the binary info struct associated with this process.\nfunc (dbp *nativeProcess) BinInfo() *proc.BinaryInfo {\n\treturn dbp.bi\n}\n\n// StartCallInjection notifies the backend that we are about to inject a function call.\nfunc (dbp *nativeProcess) StartCallInjection() (func(), error) { return func() {}, nil }\n\n// detachWithoutGroup is a helper function to detach from a process which we\n// haven't added to a process group yet.\nfunc detachWithoutGroup(dbp *nativeProcess, kill bool) error {\n\tgrp := &processGroup{procs: []*nativeProcess{dbp}}\n\treturn grp.Detach(dbp.pid, kill)\n}\n\n// Detach from the process being debugged, optionally killing it.","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/go-delve/delve/blob/a23773e6c31361e43246bc43a424ee009679b174/pkg/proc/native/proc.go#L71-L107","documentation":"WaitFor polls for a process matching a name/pid for up to waitFor.Duration. If the deadline elapses without finding a matching process, it returns 'waitfor duration expired'. It is used by Attach with the --waitfor flag.","triggerScenarios":"dlv attach --waitfor <name/pid> where no process matching the pattern appears within the configured duration (default ~ short timeout) — the loop's time check expires and pid remains 0.","commonSituations":"Attaching to a program that starts slower than the waitfor timeout; misspelled process name in waitfor; process crashing before it can be found; waitfor interval/duration flags misconfigured (duration shorter than startup time).","solutions":["Increase the waitfor duration (e.g. --waitfor-interval / longer waitfor duration flags or config)","Verify the exact process name/pid the target will have (ps aux) and correct the waitfor argument","Start the target process first, or launch it under dlv debug/exec instead of attach+waitfor","Check that the target isn't failing to start (its own startup error) — fix the target launch"],"exampleFix":"// before\ndlv attach --waitfor myserver\n// after (allow more time and poll faster)\ndlv attach --waitfor myserver --waitfor-duration 60s --waitfor-interval 100ms","handlingStrategy":"retry","validationCode":"// confirm a matching process exists (or will) before attach --waitfor\nfunc processExists(name string) bool {\n    out, err := exec.Command(\"pgrep\", \"-x\", name).Output()\n    return err == nil && len(strings.TrimSpace(string(out))) > 0\n}\nif !processExists(\"myserver\") {\n    // use a generous waitfor duration instead of the default\n}","typeGuard":null,"tryCatchPattern":"pid, err := native.WaitFor(waitFor)\nif err != nil {\n    if strings.Contains(err.Error(), \"waitfor duration expired\") {\n        return fmt.Errorf(\"no process matching %q appeared within %s; increase duration or check the process name\", waitFor.Name, waitFor.Duration)\n    }\n    return err\n}","preventionTips":["Set --waitfor-duration generously relative to the target's startup time","Double-check the exact executable/process name used in waitfor","Tune --waitfor-interval to poll frequently enough to catch short-lived matches","Ensure the target actually starts (check its logs for startup failures)"],"tags":["attach","waitfor","timeout","process-startup"],"backgroundTag":"waitfor-timeout-expired","analyzedSha":"a23773e6c31361e43246bc43a424ee009679b174","analyzedAt":"2026-08-31T15:12:45.221Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}