proper Cancellation?
See original GitHub issueCurrently the app freezes for seconds when clicking the red X of the console window – which is nearly the same as a task kill.
How to stop Socket.AcceptAsync
from “blocking” infinitely?
Further:
- what about proper disposing of IDisposables?
- async Main method does not contain a single await … why not await ProcessLinesAsync?
- no .editorconfig so first contact with ctrl+k-d reformats everything
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Frequently Asked Questions | San Francisco Proper
Guests must cancel by 3pm, 72 hours prior to arrival to avoid a penalty of one night's room and tax. Reservations with pre-paid...
Read more >“Canceled” or “Cancelled”–Which Is Correct?
Canceled and cancelled are both correct, but the spelling depends on where you call home. Learn more about these two tricky words.
Read more >How to Create a Cancellation Policy: Templates + Examples
Try these cancellation policy templates, tips, and examples to write a winning cancellation policy for your home service business.
Read more >Buyer's Remorse: The FTC's Cooling-Off Rule May Help
The Cooling-Off Rule gives you three days to cancel certain sales made at your home, workplace, ... The Seller Must Tell You About...
Read more >Right to Cancel
Where there is a right to cancel, the cancellation periods are short, typically three days, and they begin from the day you sign...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Keep in mind that this is an introductionary sample, not one that can and should be used in production directly. It’s more or less a demo to get your feets wet with pipelines. If this demo would be productized, then it would be too big for an intro.
In this demo there is no unbind on the socket, etc. and nothing that stops the accept-loop https://github.com/davidfowl/TcpEcho/blob/07ad4df181151850974219b8ebf434eee37778a4/src/Program.cs#L22-L26 You could run this server in a generic host, and leverage cancellation as well as proper disposing. But, as said before, this would be too much for an intro…
Here it is: https://github.com/davidfowl/TcpEcho/blob/07ad4df181151850974219b8ebf434eee37778a4/src/Program.cs#L24
Imagine https://github.com/davidfowl/TcpEcho/blob/07ad4df181151850974219b8ebf434eee37778a4/src/Program.cs#L25 would be written as
what would happen?
ProcessLinesAsync
is “started” for that client, the accept-loop asynchronously awaitsProcessLinesAsync
to be completedProcessLinesAsync
will complete only when reading and writing are done https://github.com/davidfowl/TcpEcho/blob/07ad4df181151850974219b8ebf434eee37778a4/src/Program.cs#L37So this would handle one client at a time and when the one is done, the next client is handled. Not very scalable.
With the implementation as is, the following happens:
ProcessLinesAsync
is “started” for that client, the returningTask
is thrown away, because we don’t want to await itSo when
ProcessLinesAsync
is started – or to be more precise, when it yields the first time (await
) – the accept-loop can await for other clients. Quite more scalable. Mature implementations like Kestrel have a more complex accept-loop.Adding two related issues: