Comments (5)
I'm very rarely going to actively advocate calling sync-over-async, and this is no exception. If it works for you, fine - but: on your head be it. Ultimately, the answer here is "pipelines is designed as an async API; there is no synchronous flush". The intent of FlushAsync()
here is for implementing back-pressure, i.e. where your writes are overtaking the limits that you've configured. When you flush, what it mostly does is make sure that the data is being actively written, but if you're over the limits, it also has the chance to say "just wait a moment until the data clears down a bit" - it will then resume the writer when there is obvious capacity in the pipe.
On a nearly empty pipe, you won't really see a problem from sync-over-async, as it will almost always be synchronous anyway; however, when you start hitting the limits (i.e. there's a backlog in the write queue), you'll find yourself blocking the writer thread(s), which could start a "spiral of death" if all the blocked writers means that there's no available pool threads to do the writing.
On your head be it.
from pipelines.sockets.unofficial.
Thanks for the fast reply. I'll look into reworking this kinda legacy code base then to support async properly, I just wanted to ensure I'm not missing something before I delve into that.
(It is indeed not the first time I have problems with my legacy sync code - I initially tried to use the StreamPipeReader
provided by the System.IO.Pipelines
package, but its TryRead
does not even ever return true
unless one called ReadAsync
before, which is why I tried your library as it happens to work in that case.)
from pipelines.sockets.unofficial.
@RayKoopa I know this is closed, but you should read up on how to properly use the "async" system. You should never use any property or method of an async call, when calling from a synchronous method. The proper action in this case would be:
Task.Run(() => client.Connection.Output.FlushAsync()).Wait();
Calling any async method and attempting to access any property or method directly from it directly, while inside a synchronous property or method, can cause a threading deadlock at any time.
from pipelines.sockets.unofficial.
@Kaelum Thanks, I'm aware of this; the project which lacked proper support for asynchrony for which I opened this issue has since been reworked/rewritten to be fully asnyc and no longer requires a workarounds.
from pipelines.sockets.unofficial.
from pipelines.sockets.unofficial.
Related Issues (20)
- Xamarin.Android crash with native exception on SocketConnection.Create HOT 2
- TLS/SSL support HOT 6
- How to find out when/if the reader/writer completed HOT 3
- Does this project only support .Net Core, instead of .Net Framework? HOT 8
- if the implementation of this library has relation ship for Rio(Winsock registered I/O extensions) in Windows? HOT 2
- Unable to wait for socket closure HOT 2
- Test: MutexSlim_ConcurrentLoadAsync_DisableContext - fails on my machine
- Test: ConnectTests.Connect - Fails on my machine HOT 1
- Test: BufferWriterDoesNotLeak also fails on my machine
- Set unsafeSuppressExecutionContextFlow on SocketAsyncEventArgs HOT 3
- Loopback fast path is deprected on Windows and can cause high cpu on Win Server 2019 HOT 2
- Pump a pair of PipeReader/PipeWriter
- Investigating SemaphoreSlim on net6.0+ HOT 1
- Unnecessary _queue.Count check in DedicatedThreadPoolPipeScheduler.RunWorkLoop HOT 7
- netstandard2.1 DoReceive fails on Zero Length Reads on Mono HOT 1
- Thread Safety Violation Warnings found by InferSharp static analysis tool HOT 3
- Trim and AOT warnings in Delegates and PerTypeHelpers HOT 3
- Fix Thread Safety and other static code analysis issues reported by Infer#
- Improve package readme
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pipelines.sockets.unofficial.