Add timeout for I/O waitgroups
Closes #3286 This and a combination of a couple Docker changes are needed to fully resolve the issue on the Docker side. However, this ensures that after processes exit, we still leave some time for the I/O to fully flush before closing. Without this timeout, the delete methods would block forever. Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
parent
111b082e20
commit
245052243d
@ -106,7 +106,7 @@ func (e *execProcess) Delete(ctx context.Context) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (e *execProcess) delete(ctx context.Context) error {
|
func (e *execProcess) delete(ctx context.Context) error {
|
||||||
e.wg.Wait()
|
waitTimeout(ctx, &e.wg, 2*time.Second)
|
||||||
if e.io != nil {
|
if e.io != nil {
|
||||||
for _, c := range e.closers {
|
for _, c := range e.closers {
|
||||||
c.Close()
|
c.Close()
|
||||||
|
@ -284,7 +284,7 @@ func (p *Init) Delete(ctx context.Context) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *Init) delete(ctx context.Context) error {
|
func (p *Init) delete(ctx context.Context) error {
|
||||||
p.wg.Wait()
|
waitTimeout(ctx, &p.wg, 2*time.Second)
|
||||||
err := p.runtime.Delete(ctx, p.id, nil)
|
err := p.runtime.Delete(ctx, p.id, nil)
|
||||||
// ignore errors if a runtime has already deleted the process
|
// ignore errors if a runtime has already deleted the process
|
||||||
// but we still hold metadata and pipes
|
// but we still hold metadata and pipes
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
package proc
|
package proc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
@ -143,3 +144,21 @@ func (p *pidFile) Path() string {
|
|||||||
func (p *pidFile) Read() (int, error) {
|
func (p *pidFile) Read() (int, error) {
|
||||||
return runc.ReadPidFile(p.path)
|
return runc.ReadPidFile(p.path)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// waitTimeout handles waiting on a waitgroup with a specified timeout.
|
||||||
|
// this is commonly used for waiting on IO to finish after a process has exited
|
||||||
|
func waitTimeout(ctx context.Context, wg *sync.WaitGroup, timeout time.Duration) error {
|
||||||
|
ctx, cancel := context.WithTimeout(ctx, timeout)
|
||||||
|
defer cancel()
|
||||||
|
done := make(chan struct{}, 1)
|
||||||
|
go func() {
|
||||||
|
wg.Wait()
|
||||||
|
close(done)
|
||||||
|
}()
|
||||||
|
select {
|
||||||
|
case <-done:
|
||||||
|
return nil
|
||||||
|
case <-ctx.Done():
|
||||||
|
return ctx.Err()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user