Skip to content
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

close engine connection when ping fails #568

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions engine/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,8 @@ func (e *Engine) Ping(ctx context.Context) error {
_, err := e.client.Ping(ctx)
return err
}

// CloseConn close connection
func (e *Engine) CloseConn() error {
return e.client.Close()
}
1 change: 1 addition & 0 deletions engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
type API interface {
Info(ctx context.Context) (*enginetypes.Info, error)
Ping(ctx context.Context) error
CloseConn() error

Execute(ctx context.Context, ID string, config *enginetypes.ExecConfig) (result string, stdout, stderr io.ReadCloser, stdin io.WriteCloser, err error)
ExecResize(ctx context.Context, ID, result string, height, width uint) (err error)
Expand Down
5 changes: 5 additions & 0 deletions engine/factory/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,11 @@ func validateEngine(ctx context.Context, engine engine.API, timeout time.Duratio
utils.WithTimeout(ctx, timeout, func(ctx context.Context) {
err = engine.Ping(ctx)
})
if err != nil {
if closeErr := engine.CloseConn(); closeErr != nil {
log.Errorf(ctx, "[validateEngine] close conn error: %v", closeErr)
}
}
return err
}

Expand Down
5 changes: 5 additions & 0 deletions engine/fake/fake.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ func (f *Engine) Ping(ctx context.Context) error {
return f.DefaultErr
}

// CloseConn .
func (f *Engine) CloseConn() error {
return nil
}

// Execute .
func (f *Engine) Execute(ctx context.Context, ID string, config *enginetypes.ExecConfig) (result string, stdout, stderr io.ReadCloser, stdin io.WriteCloser, err error) {
return "", nil, nil, nil, f.DefaultErr
Expand Down
14 changes: 14 additions & 0 deletions engine/mocks/API.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions engine/virt/virt.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ func (v *Virt) Ping(ctx context.Context) error {
return err
}

// CloseConn closes the connection.
func (v *Virt) CloseConn() error {
return v.client.Close()
}

// Execute executes a command in vm
func (v *Virt) Execute(ctx context.Context, ID string, config *enginetypes.ExecConfig) (pid string, stdout, stderr io.ReadCloser, stdin io.WriteCloser, err error) {
if config.Tty {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ require (
github.com/opencontainers/runc v1.0.0-rc95 // indirect
github.com/patrickmn/go-cache v2.1.0+incompatible
github.com/pkg/errors v0.9.1
github.com/projecteru2/libyavirt v0.0.0-20211217082140-493b61aa9b0d
github.com/projecteru2/libyavirt v0.0.0-20220328133352-2a6302e90fc9
github.com/prometheus/client_golang v1.11.0
github.com/sanity-io/litter v1.5.1
github.com/sirupsen/logrus v1.7.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,8 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI=
github.com/projecteru2/libyavirt v0.0.0-20211217082140-493b61aa9b0d h1:BMFqsvIB3nmK5l53nz8r2ndK8//T0njciu5nr/kj9A4=
github.com/projecteru2/libyavirt v0.0.0-20211217082140-493b61aa9b0d/go.mod h1:FOc+hWBMLsMrmx5p3/moizKeSomedZPNwB6LhS+kEnE=
github.com/projecteru2/libyavirt v0.0.0-20220328133352-2a6302e90fc9 h1:7atvx2788Nf+HvY5uZFLlogjplvvF7iw5nWI/8UkjoY=
github.com/projecteru2/libyavirt v0.0.0-20220328133352-2a6302e90fc9/go.mod h1:FOc+hWBMLsMrmx5p3/moizKeSomedZPNwB6LhS+kEnE=
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDft0ttaMvbicHlPoso=
github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo=
Expand Down