mirror of
https://github.com/yusing/godoxy.git
synced 2025-05-20 12:42:34 +02:00
fixed possible resource leak
This commit is contained in:
parent
a11ce46028
commit
d39b68bfd8
1 changed files with 10 additions and 6 deletions
|
@ -33,6 +33,8 @@ var (
|
|||
DockerFilterUnpause = filters.Arg("event", string(docker_events.ActionUnPause))
|
||||
|
||||
NewDockerFilter = filters.NewArgs
|
||||
|
||||
dockerWatcherRetryInterval = 3 * time.Second
|
||||
)
|
||||
|
||||
func DockerrFilterContainerName(name string) filters.KeyValuePair {
|
||||
|
@ -56,6 +58,8 @@ func (w DockerWatcher) EventsWithOptions(ctx context.Context, options DockerList
|
|||
errCh := make(chan E.NestedError)
|
||||
started := make(chan struct{})
|
||||
|
||||
eventsCtx, eventsCancel := context.WithCancel(ctx)
|
||||
|
||||
go func() {
|
||||
defer close(eventCh)
|
||||
defer close(errCh)
|
||||
|
@ -80,12 +84,12 @@ func (w DockerWatcher) EventsWithOptions(ctx context.Context, options DockerList
|
|||
case <-ctx.Done():
|
||||
return
|
||||
default:
|
||||
time.Sleep(3 * time.Second)
|
||||
time.Sleep(dockerWatcherRetryInterval)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cEventCh, cErrCh := w.client.Events(ctx, options)
|
||||
cEventCh, cErrCh := w.client.Events(eventsCtx, options)
|
||||
started <- struct{}{}
|
||||
|
||||
for {
|
||||
|
@ -118,13 +122,13 @@ func (w DockerWatcher) EventsWithOptions(ctx context.Context, options DockerList
|
|||
case <-ctx.Done():
|
||||
return
|
||||
default:
|
||||
if D.IsErrConnectionFailed(err) {
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
eventsCancel()
|
||||
time.Sleep(dockerWatcherRetryInterval)
|
||||
eventsCtx, eventsCancel = context.WithCancel(ctx)
|
||||
cEventCh, cErrCh = w.client.Events(ctx, options)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}()
|
||||
<-started
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue