Semaphore timeout while using pipes?
I'm using named pipes two communicate between two processes on the same computer. Quite frequently (and randomly), however, a ConnectNamedPipe() operation fails and GetLastError() returns 121, which according to MSDN is due to a semaphore timeout. Can someone explain what pipes have to do with semaphores and why I could be getting this error?
EDIT: Sorry, I made a mistake. It is CreateFile(), not ConnectNamedPipe(), that produces the error.
Re: Semaphore timeout while using pipes?
one process creates the named pipe via CreateNamedPipe() and waits for clients via ConnectNamedPipe(). are there multiple connections to the pipe created in the first process on the second process?
Kuphryn
Re: Semaphore timeout while using pipes?
Quote:
Originally Posted by kuphryn
one process creates the named pipe via CreateNamedPipe() and waits for clients via ConnectNamedPipe(). are there multiple connections to the pipe created in the first process on the second process?
Kuphryn
The second process keeps connecting to and disconnecting from the first process' pipe using CreateFile() and CloseHandle(). It is CreateFile() in the second process that produces the error code 121 frequently, usually after connecting and disconnecting multiple times.
Re: Semaphore timeout while using pipes?
logic is correct. multiple threads? possible that you open more pipes than close pipe?
Kuphryn
Re: Semaphore timeout while using pipes?
Quote:
Originally Posted by kuphryn
logic is correct. multiple threads? possible that you open more pipes than close pipe?
Kuphryn
Nope, both processes are single-threaded. The use of pipes is well encapsulated in functions that start by connecting the pipe and end by disconnecting it, so I'd say it's unlikely I open the pipes more than I close them.
I changed my code to decrease the number of connects/disconnects, preferring to stay connected until a larger amount of data is transferred, and the errors have significantly decreased in frequency, but still come up once in a while and undermine the reliability of my code.
I'm wondering if it has something to do with the amount of pipe instances I'm allowing when I'm creating the pipe, though I'm not sure how that could be the problem since the pipes are only being used between two processes...
EDIT: I have increased the number of allowed pipe instances that I specify at the time of pipe creation, but it had no effect. The errors continue to appear very randomly. :confused: