Skip to content

Commit d3887f6

Browse files
Merge pull request #2519 from jterry75/various_win_fixes
Various Windows fixes to support the runtime v2 shim workflow
2 parents 123de20 + dcb9057 commit d3887f6

3 files changed

Lines changed: 26 additions & 12 deletions

File tree

cio/io_windows.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"fmt"
2121
"io"
2222
"net"
23-
"sync"
2423

2524
winio "github.com/Microsoft/go-winio"
2625
"github.com/containerd/containerd/log"
@@ -41,7 +40,6 @@ func NewFIFOSetInDir(_, id string, terminal bool) (*FIFOSet, error) {
4140

4241
func copyIO(fifos *FIFOSet, ioset *Streams) (*cio, error) {
4342
var (
44-
wg sync.WaitGroup
4543
set []io.Closer
4644
)
4745

@@ -85,9 +83,7 @@ func copyIO(fifos *FIFOSet, ioset *Streams) (*cio, error) {
8583
}(l)
8684
set = append(set, l)
8785

88-
wg.Add(1)
8986
go func() {
90-
defer wg.Done()
9187
c, err := l.Accept()
9288
if err != nil {
9389
log.L.WithError(err).Errorf("failed to accept stdout connection on %s", fifos.Stdout)
@@ -115,9 +111,7 @@ func copyIO(fifos *FIFOSet, ioset *Streams) (*cio, error) {
115111
}(l)
116112
set = append(set, l)
117113

118-
wg.Add(1)
119114
go func() {
120-
defer wg.Done()
121115
c, err := l.Accept()
122116
if err != nil {
123117
log.L.WithError(err).Errorf("failed to accept stderr connection on %s", fifos.Stderr)

cmd/ctr/commands/tasks/tasks_windows.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,16 @@ func HandleConsoleResize(ctx gocontext.Context, task resizer, con console.Consol
5959

6060
// NewTask creates a new task
6161
func NewTask(ctx gocontext.Context, client *containerd.Client, container containerd.Container, _ string, tty, nullIO bool, ioOpts []cio.Opt, opts ...containerd.NewTaskOpts) (containerd.Task, error) {
62-
ioCreator := cio.NewCreator(append([]cio.Opt{cio.WithStdio}, ioOpts...)...)
62+
var ioCreator cio.Creator
6363
if tty {
64-
ioCreator = cio.NewCreator(append([]cio.Opt{cio.WithStdio, cio.WithTerminal}, ioOpts...)...)
65-
}
66-
if nullIO {
67-
if tty {
64+
if nullIO {
6865
return nil, errors.New("tty and null-io cannot be used together")
6966
}
67+
ioCreator = cio.NewCreator(append([]cio.Opt{cio.WithStdio, cio.WithTerminal}, ioOpts...)...)
68+
} else if nullIO {
7069
ioCreator = cio.NullIO
70+
} else {
71+
ioCreator = cio.NewCreator(append([]cio.Opt{cio.WithStdio}, ioOpts...)...)
7172
}
7273
return container.NewTask(ctx, ioCreator)
7374
}

runtime/v2/shim/util_windows.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"context"
2121
"fmt"
2222
"net"
23+
"os"
2324
"syscall"
2425
"time"
2526

@@ -48,7 +49,25 @@ func SocketAddress(ctx context.Context, id string) (string, error) {
4849

4950
// AnonDialer returns a dialer for a npipe
5051
func AnonDialer(address string, timeout time.Duration) (net.Conn, error) {
51-
return winio.DialPipe(address, &timeout)
52+
var c net.Conn
53+
var lastError error
54+
start := time.Now()
55+
for {
56+
remaining := timeout - time.Now().Sub(start)
57+
if remaining <= 0 {
58+
lastError = errors.Errorf("timed out waiting for npipe %s", address)
59+
break
60+
}
61+
c, lastError = winio.DialPipe(address, &remaining)
62+
if lastError == nil {
63+
break
64+
}
65+
if !os.IsNotExist(lastError) {
66+
break
67+
}
68+
time.Sleep(10 * time.Millisecond)
69+
}
70+
return c, lastError
5271
}
5372

5473
// NewSocket returns a new npipe listener

0 commit comments

Comments
 (0)