-
-
Notifications
You must be signed in to change notification settings - Fork 117
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
C# large streams do not permit async event handlers #186
Comments
Would it be possible to create a callback for async streams? How else am I supposed to use |
Hi @Niproblema perhaps I'm not understanding the problem correctly, but, you can't have multiple readers concurrently on the underlying socket. If I'm understanding what you're asking, you want one stream to be handled by one event, and, another stream handled by a different event. Is that correct? |
@jchristn I want to have multiple clients connected to one tcp server. As far as I understand each client is anyway using own dedicated server socket, right? So I should be able to stream files from multiple clients to a single server concurrently, right? It would defeat it's purpose if all but one clients were waiting for the one to finish. However, I am talking about a different issue here. Server library exposes new stream through a C# event handler. However event handlers are single thread synchronous methods. I cannot use async within them without either blocking the original thread with calling |
Looking at WatsonTcpServer.cs in
I don't get this part. Why call new stream method with Wouldn't this lead to thread pool exhaustion, as I always have to block a thread provided by the event handler in order to read the stream contents. Having many concurrent clients this might be problematic, as all of them shall have concurrently blocked threads. |
Or perhaps even better, change |
The reason in the first case, where If you prefer the library do it, you can always set that parameter |
Thanks for reply. Answered exactly what I was rambling about :)
I understand that but having true async event handler or a callback still allows that while also allowing async reading, which according to the documentation should be faster:
Seems like a win win to me if you included async event handler or async callback. Even if I didn't use async methods, having async event handler allows me to do either approach.
That's exactly the issue I am having by returning event handler task instead of blocking thread and awaiting task.
|
Hi @Niproblema thank you, I think I'm on the same page now. Let me jump into the source when I get a moment and see if I can find a way to make this work. Cheers |
I have figured that sending large streams just does not work when using async.
For example,
Client side:
where
GetStream()
generates some random large stream. E.g.Server side:
This works perfectly, but I require non blocking approach...
In this example deadlock occurs and the
copyTo()
never returns. Meanwhile the client receives successful sendAsync and returns. This is true only when stream is overMaxProxiedStreamSize
. (See #168 (reply in thread)_)The text was updated successfully, but these errors were encountered: