Skip to content

Commit

Permalink
Fix premature Close() of docker client
Browse files Browse the repository at this point in the history
Signed-off-by: Matej Vasek <mvasek@redhat.com>
  • Loading branch information
matejvasek committed Jun 13, 2022
1 parent df7b573 commit f585eb4
Showing 1 changed file with 13 additions and 16 deletions.
29 changes: 13 additions & 16 deletions s2i/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,19 @@ func (b *Builder) Build(ctx context.Context, f fn.Function) (err error) {

// Create the S2I builder instance if not overridden
if b.impl == nil {
if b.impl, err = newImpl(ctx, cfg); err != nil {
var client dockerClient.CommonAPIClient
client, _, err = docker.NewClient(dockerClient.DefaultDockerHost)
if err != nil {
return
}
defer client.Close()

if isPodman(ctx, client) {
client = podmanDockerClient{client}
}

b.impl, _, err = strategies.Strategy(client, cfg, build.Overrides{})
if err != nil {
return
}
}
Expand Down Expand Up @@ -157,18 +169,3 @@ func builderImage(f fn.Function) (string, error) {

return "", ErrRuntimeNotSupported
}

// new S2I implementation using a docker client wrapped as necessary in the
// case of podman.
func newImpl(ctx context.Context, cfg *api.Config) (impl build.Builder, err error) {
client, _, err := docker.NewClient(dockerClient.DefaultDockerHost)
if err != nil {
return
}
defer client.Close()
if isPodman(ctx, client) {
client = podmanDockerClient{client}
}
impl, _, err = strategies.Strategy(client, cfg, build.Overrides{})
return
}

0 comments on commit f585eb4

Please sign in to comment.