Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it Thread Safe? #6

Open
marcherNYC opened this issue Feb 11, 2016 · 4 comments
Open

Is it Thread Safe? #6

marcherNYC opened this issue Feb 11, 2016 · 4 comments

Comments

@marcherNYC
Copy link

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

@davidgrupp
Copy link

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.

@marcherNYC
Copy link
Author

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
Copy link
Author

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!

@thaxy
Copy link

thaxy commented Apr 6, 2017

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants