-
-
Notifications
You must be signed in to change notification settings - Fork 605
fix: return an error when docker host cannot be retrieved #3613
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,8 +31,9 @@ var ( | |
| ) | ||
|
|
||
| var ( | ||
| dockerHostCache string | ||
| dockerHostOnce sync.Once | ||
| dockerHostCache string | ||
| dockerHostErrCache error | ||
| dockerHostOnce sync.Once | ||
| ) | ||
|
|
||
| var ( | ||
|
|
@@ -85,16 +86,18 @@ var dockerHostCheck = func(ctx context.Context, host string) error { | |
| // 6. Rootless docker socket path. | ||
| // 7. Else, because the Docker host is not set, it panics. | ||
| func MustExtractDockerHost(ctx context.Context) string { | ||
| dockerHostOnce.Do(func() { | ||
| cache, err := extractDockerHost(ctx) | ||
| if err != nil { | ||
| panic(err) | ||
| } | ||
| host, err := ExtractDockerHost(ctx) | ||
| if err != nil { | ||
| panic(err) | ||
| } | ||
| return host | ||
| } | ||
|
|
||
| dockerHostCache = cache | ||
| func ExtractDockerHost(ctx context.Context) (string, error) { | ||
| dockerHostOnce.Do(func() { | ||
| dockerHostCache, dockerHostErrCache = extractDockerHost(ctx) | ||
| }) | ||
|
|
||
| return dockerHostCache | ||
| return dockerHostCache, dockerHostErrCache | ||
| } | ||
|
Comment on lines
+96
to
101
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do not cache Docker host extraction errors process-wide. At Line 97, Suggested fix (cache success only, allow retry on errors) var (
- dockerHostCache string
- dockerHostErrCache error
- dockerHostOnce sync.Once
+ dockerHostCache string
+ dockerHostCached bool
+ dockerHostMu sync.Mutex
)
@@
func ExtractDockerHost(ctx context.Context) (string, error) {
- dockerHostOnce.Do(func() {
- dockerHostCache, dockerHostErrCache = extractDockerHost(ctx)
- })
- return dockerHostCache, dockerHostErrCache
+ dockerHostMu.Lock()
+ defer dockerHostMu.Unlock()
+
+ if dockerHostCached {
+ return dockerHostCache, nil
+ }
+
+ host, err := extractDockerHost(ctx)
+ if err != nil {
+ return "", err
+ }
+
+ dockerHostCache = host
+ dockerHostCached = true
+ return dockerHostCache, nil
}Also applies to: 34-36 🤖 Prompt for AI Agents |
||
|
|
||
| // MustExtractDockerSocket Extracts the docker socket from the different alternatives, removing the socket schema and | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.