Giter Site home page Giter Site logo

Comments (5)

mgravell avatar mgravell commented on September 21, 2024 1

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.

RayKoopa avatar RayKoopa commented on September 21, 2024

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.

Kaelum avatar Kaelum commented on September 21, 2024

@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.

RayKoopa avatar RayKoopa commented on September 21, 2024

@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.

mgravell avatar mgravell commented on September 21, 2024

from pipelines.sockets.unofficial.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.