Commit Graph
25 Commits
Author SHA1 Message Date
John Starks a6d595ae73 Merge pull request #80 from nanomsg/norace2
fixes #67 DialPipe problem with multiple calls / waiting for busy pipe
2018-07-19 15:37:18 -07:00
Garrett D'Amore effecfb659 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.
2018-07-18 12:07:29 -07:00
John Starks 3eabd1969d Clean up message mode pipe handling, add test 2018-06-25 09:31:55 -07:00
Garrett D'Amore ecd994be06 fixes #67 DialPipe problem with multiple calls / waiting for busy pipe
This changes a few things to try to ensure that we never wind up with
a result of ERROR_FILE_NOT_FOUND, due to a race between closing the
last pipe instance and opening the next.

First we keep an "open" client instance (unused) while the listener
is open, so that we are guaranteed to always have an active pipe
instance.  This means attempts to open while no other instances exist
result in ERROR_PIPE_BUSY instead of ERROR_FILE_NOT_FOUND.

Second we have changed the loop for dialing to eliminate a race condition
that is more or less inherent in WaitNamedPipe when synchronizing with
CreateFile.  The real timeout needs to be some larger value than the
WaitNamedPipe timeout, and furthermore WaitNamedPipe is not very nice
with the Go runtime, since it is a blocking system call.  Instead we
just put the goroutine to sleep for 10 milliseconds, and keep retrying
the CreateFile until the maximum timeout is reached.  If no timeout is
specified we assume a reasonable and large default of 5 seconds, which is
similar to a TCP connection timeout.

This isn't perfect, as a client attempting to connect to an extremely
busy pipe server can be starved out by other clients coming in while
it is in that brief sleep, but this potential race was already present
with WaitNamedPipe.  The numerous retries (by default 500 retries!)
mean its pretty unlikely to occur, and if a single client hits the
race once, it has an excellent chance of getting in the next cycle.

(A real "fix" that is completely race free and fair would require
changes in the underlying Named Pipe implementation, or some other
kind of external coordination.)
2018-06-24 11:39:09 -07:00
Tejaswini Duggaraju 211d6ebb39 Allow for message pipes in message readmode for Windows named pipes. 2018-05-25 12:13:39 -07:00
John Starks ae842e48e0 pipe: Resolve race between close and connect
This change resolves the issue where Accept() returns ERROR_NO_DATA
because the client closes the connection immediately. It resolves
the race by ignoring that particular connection and waiting on a
new one.
2018-01-09 13:28:13 -08:00
Francisco Souza 6f65f5291e Copy pointer to prevent data race on pipe connection
Closes #62.
2017-07-25 23:33:44 -04:00
Darren Stahl 18d7347919 RtlCopyMemory is not available on Nanoserver use builtin copy instead
Signed-off-by: Darren Stahl <darst@microsoft.com>
2017-05-23 17:26:29 -07:00
Darren Stahl a64f284add Move f.wg.Done() to Read and Write to avoid leaking handles
Signed-off-by: Darren Stahl <darst@microsoft.com>
2017-05-19 15:42:58 -07:00
John Starks d311c76e77 Merge pull request #51 from darrenstahlmsft/NoCGO
Remove cgo as a dependency added by #49
2017-05-08 14:01:43 -07:00
Darren Stahl de045f765f Remove cgo as a dependency added by #48
Signed-off-by: Darren Stahl <darst@microsoft.com>
2017-05-05 16:39:41 -07:00
Darren Stahl 899dbf3ba5 Apply read and write deadlines to pending IO
In order to upgrade to go1.8 all IO operations
including previous pending IO must have the deadline
set when SetReadDeadline or SetWriteDeadline is called

Signed-off-by: Darren Stahl <darst@microsoft.com>
2017-05-05 14:53:42 -07:00
Darren Stahl 23ad5a714c Allocate securityDescriptor in C memory
Signed-off-by: Darren Stahl <darst@microsoft.com>
2017-05-03 12:46:54 -07:00
Simon Ferquel 7c7d6b461c Flush file buffers on CloseWrite
This forces any pending data to be sent to the remote party before
emitting the 0-length EOF message, to make sure it appears as a seperate
message.

This fixes the "TestEchoWithMessaging" test

Signed-off-by: Simon Ferquel <simon.ferquel@docker.com>
2017-03-17 16:57:20 +01:00
Cezar Sa Espinola 94c0518b08 Include build tags to allow go get on non-Windows platforms. Fixes #30 2016-10-06 18:00:50 -03:00
John Starks b12bd3ac52 Let clients set pipe buffer sizes 2016-03-15 11:59:27 -07:00
John Starks 36f4e701c4 Add support for CloseWrite() to pipes
This change adds support for message mode pipes and uses them to support
CloseWrite() to better match TCP and UNIX sockets. Message mode pipes
support writing and (optionally) reading data in message-sized chunks.
This is useful for us because when in this mode a zero-sized message can
be read. We use this zero-sized message to signal that no more writes will
arrive. This is not standard practice in Windows, but it is a reasonable
compromise.
2016-03-15 11:58:02 -07:00
John Starks f011a81ddc Add interface to BackupRead/BackupWrite 2016-02-18 20:40:32 -08:00
John Starks 89bdf52a5b Add routine for looking up account names
Signed-off-by: John Starks <jostarks@microsoft.com>
2016-01-31 16:08:10 -08:00
John Starks fe517a5118 Misc. cleanup
Signed-off-by: John Starks <jostarks@microsoft.com>
2016-01-31 14:18:04 -08:00
John Starks 3aa597fc55 Open pipe client with anonymous security
This ensures that the pipe server cannot impersonate or even identify
the user that has connected to the pipe. This is a good default to
prevent malicious squatting on a named pipe name.

Signed-off-by: John Starks <jostarks@microsoft.com>
2016-01-31 14:03:47 -08:00
John Starks 99eef7be8d Ensure DialPipe times eventually by default
Signed-off-by: John Starks <jostarks@microsoft.com>
2016-01-31 14:00:21 -08:00
John Starks 3191792462 Fix errors to better match net package
Signed-off-by: John Starks <jostarks@microsoft.com>
2016-01-31 13:47:08 -08:00
John Starks b0d265e6c2 Ensure win32PipeListener.Close() correctly aborts Listen() calls
Signed-off-by: John Starks <jostarks@microsoft.com>
2016-01-31 13:46:55 -08:00
John Starks f001f808a9 Add file and pipe Windows wrappers
This includes Reader, Writer, and Closer interfaces on top of
Windows file handles in a way that does not block the system thread
while the IO is outstanding.

This also includes net.Listener and net.Conn for named pipes.
2016-01-30 18:11:47 -08:00