Skip to content

Commit effecfb

Browse files
committed
Reduce the timeout to 2 seconds, and close the client handle.
We can safely close the client handle, because the server side is not closed, and thsi keeps our hold on the pipe instance.
1 parent ecd994b commit effecfb

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

pipe.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ func DialPipe(path string, timeout *time.Duration) (net.Conn, error) {
140140
if timeout != nil {
141141
absTimeout = time.Now().Add(*timeout)
142142
} else {
143-
absTimeout = time.Now().Add(time.Second * 5)
143+
absTimeout = time.Now().Add(time.Second * 2)
144144
}
145145
var err error
146146
var h syscall.Handle
@@ -200,7 +200,6 @@ type acceptResponse struct {
200200

201201
type win32PipeListener struct {
202202
firstHandle syscall.Handle
203-
clientHandle syscall.Handle
204203
path string
205204
securityDescriptor []byte
206205
config PipeConfig
@@ -303,8 +302,6 @@ func (l *win32PipeListener) listenerRoutine() {
303302
}
304303
syscall.Close(l.firstHandle)
305304
l.firstHandle = 0
306-
syscall.Close(l.clientHandle)
307-
l.clientHandle = 0
308305
// Notify Close() and Accept() callers that the handle has been closed.
309306
close(l.doneCh)
310307
}
@@ -362,9 +359,13 @@ func ListenPipe(path string, c *PipeConfig) (net.Listener, error) {
362359
syscall.Close(h)
363360
return nil, err
364361
}
362+
// Close the client handle. The server side of the instance will
363+
// still be busy, leading to ERROR_PIPE_BUSY instead of
364+
// ERROR_NOT_FOUND, as long as we don't close the server handle,
365+
// or disconnect the client with DisconnectNamedPipe.
366+
syscall.Close(h2)
365367
l := &win32PipeListener{
366368
firstHandle: h,
367-
clientHandle: h2,
368369
path: path,
369370
securityDescriptor: sd,
370371
config: *c,

0 commit comments

Comments
 (0)