named-pipe-wrapper icon indicating copy to clipboard operation
named-pipe-wrapper copied to clipboard

Is it Thread Safe?

Open marcherNYC opened this issue 9 years ago • 4 comments

Hi,

Am getting this message every time multiple threads try to write to a single pipe. Is it thread safe? I locked on a client to push messages one at a time, but still getting this error. Once you see it the whole connection is dead.

Any suggestions?

Thanks!

Object Graph cannot be null.\r\nParameter name: graph

at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Serialize(Object graph, Header[] inHeaders, __BinaryWriter serWriter, Boolean fCheck) at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph, Header[] headers, Boolean fCheck) at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph) at NamedPipeWrapper.IO.PipeStreamWriter1.Serialize(T obj) in C:\Projects\NamedPipeWrapper\NamedPipeWrapper\IO\PipeStreamWriter.cs:line 42 at NamedPipeWrapper.IO.PipeStreamWriter1.WriteObject(T obj) in C:\Projects\NamedPipeWrapper\NamedPipeWrapper\IO\PipeStreamWriter.cs:line 72 at NamedPipeWrapper.IO.PipeStreamWrapper2.WriteObject(TWrite obj) in C:\Projects\NamedPipeWrapper\NamedPipeWrapper\IO\PipeStreamWrapper.cs:line 106 at NamedPipeWrapper.NamedPipeConnection2.WritePipe() in C:\Projects\NamedPipeWrapper\NamedPipeWrapper\NamedPipeConnection.cs:line 167 at NamedPipeWrapper.Threading.Worker.DoWorkImpl(Object oAction) in C:\Projects\NamedPipeWrapper\NamedPipeWrapper\Threading\Worker.cs:line 46

marcherNYC avatar Feb 11 '16 16:02 marcherNYC

If your threads are using the same instance of a client or server it wont be threadsafe. If you use different clients/servers for each thread you should be fine. I've used multiple clients in different threads successfully and didn't run into the issue you've found.

I'd also like to point out that the original author acdvorak doesn't support this repo anymore (it's a dead repo basically) and you should take a look at: https://github.com/reliablehosting/named-pipe-wrapper which is a more active fork with other bug fixes applied.

davidgrupp avatar Feb 11 '16 16:02 davidgrupp

Thanks for the update. Can it handle 100+ connections? What are the costs associated with establishing and dropping them? Any plans on making it thread safe?

marcherNYC avatar Feb 11 '16 17:02 marcherNYC

FYI - tested with 12 clients (1 per thread with client instance access enforced through Thread.CurrentThread). Same problem - either pipe breaks or Graph is null in serialization or client just disconnects for no reason. Tried putting locks inside of a Writer, but it is a wack a mole - the problem just moves to some other place and still nothing works. To reproduce the problem simply create 10 clients against 1 server - then throw 100000 requests from each at the same time.

One instance of a client per 1 instance of a server? What is the point of that? How do I know how many threads/clients would I have at any time - what if I have 5 processes with 12-20 threads each calling on a single Server to do some computation - are you saying I need 100 servers then and always call the right server from the right client or else it all blows up? Hope it is just my misunderstanding of your comment.

Would really appreciate your specific recipe on how to get this to work with multiple threads.

Thanks!

marcherNYC avatar Feb 11 '16 18:02 marcherNYC

Any progress here? Would it be an option to lock the Send/Push message on the client and server side?

thaxy avatar Apr 06 '17 18:04 thaxy