{"record":{"id":"1b272c4f3793cf09","repo":"juicedata/juicefs","slug":"timeout-after-s-w","errorCode":null,"errorMessage":"timeout after %s: %w","messagePattern":"timeout after (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/utils/utils.go","lineNumber":125,"sourceCode":"\treturn ips, nil\n}\n\nfunc WithTimeout(pCtx context.Context, f func(context.Context) error, timeout time.Duration) error {\n\tdone := make(chan error, 1)\n\tt := time.NewTimer(timeout)\n\tctx, cancel := context.WithCancel(pCtx)\n\tdefer cancel()\n\tdefer t.Stop()\n\tgo func() {\n\t\tdone <- f(ctx)\n\t}()\n\tselect {\n\tcase <-ctx.Done():\n\t\treturn ctx.Err()\n\tcase err := <-done:\n\t\treturn err\n\tcase <-t.C:\n\t\treturn fmt.Errorf(\"timeout after %s: %w\", timeout, ErrFuncTimeout)\n\t}\n}\n\nfunc RemovePassword(uri string) string {\n\tp := strings.LastIndex(uri, \"@\")\n\tif p < 0 {\n\t\treturn uri\n\t}\n\tsp := strings.Index(uri, \"://\") + 3\n\tif sp == 2 {\n\t\tsp = 0\n\t}\n\tcp := strings.Index(uri[sp:], \":\")\n\tif cp < 0 || sp+cp > p {\n\t\treturn uri\n\t}\n\treturn uri[:sp+cp] + \":****\" + uri[p:]\n}","sourceCodeStart":107,"sourceCodeEnd":143,"githubUrl":"https://github.com/juicedata/juicefs/blob/c9a67b23e8e08ec23ec331aa6f1675e2319e921c/pkg/utils/utils.go#L107-L143","documentation":"WithTimeout runs fn in a goroutine and returns ErrFuncTimeout wrapped as 'timeout after %s: %w' when the operation does not finish within the given duration. The wrapped ctx.Err() path is separate; this error specifically means the timer fired first.","triggerScenarios":"Any wrapped operation (copyFile, getPprofPort, collectSpecialFile, debug, getCmdMount, mount) exceeding its timeout — slow disk copy, hung subprocess, stalled mount, profile collection on a busy process.","commonSituations":"Large file copies during warm-up/upgrade; `juicefs debug` collecting info from a hung mount; slow or wedged FUSE mount at startup.","solutions":["Increase the relevant timeout for the operation","Investigate why the underlying operation hangs (logs, strace, mount status)","Retry once the system is responsive","For mount failures, check FUSE device availability and metadata engine connectivity"],"exampleFix":"// before\nerr := utils.WithTimeout(fn, 5*time.Second)\n// after\nerr := utils.WithTimeout(fn, 60*time.Second)","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := utils.WithTimeout(fn, timeout); err != nil {\n  if errors.Is(err, utils.ErrFuncTimeout) { /* retry or raise timeout */ }\n  return err\n}","preventionTips":["Size timeouts to worst-case operation duration (large copies, slow mounts)","Log operation start/end to spot near-timeout operations","Avoid wrapping unbounded blocking calls without generous timeouts"],"tags":["timeout","goroutine"],"backgroundTag":"request-timeout","analyzedSha":"c9a67b23e8e08ec23ec331aa6f1675e2319e921c","analyzedAt":"2026-09-06T17:55:48.476Z","contentChangedAt":"2026-09-06T17:55:48.476Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}