TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Asynchronous clean-up

87 pointsby hermanradtkeabout 1 year ago

11 comments

jandrewrogersabout 1 year ago
This post is primarily about Rust but the issues raised generalize to async models in any programming language. The tradeoffs between approaches are severe enough that it is desirable, at least in a systems language, to preserve enough flexibility that the model generalizes to different contexts without loss of performance or robustness. Furthermore, async tends to erode modularity in code because async behavior, which is tightly coupled to internal design choices, becomes part of the functional contract. There are all kinds of interesting edge cases around things like bounding worst-case resource pseudo-leakage that you simply don’t need to think about in synchronous code.<p>This is not to suggest that async models are a bad idea. They just have a higher level of intrinsic complexity and language support is immature. The benefit is qualitatively better scalability and performance, so there is a purpose behind using async models.
评论 #39499954 未加载
pdimitarabout 1 year ago
I am likely not even at 10% of the competence of the author but I can&#x27;t help but notice the continuously mentioned struggle of &quot;but what if we cancel the cancellation?&quot; -- which to me seems to be the wrong question to ask. IMO it should not be possible. It should be <i>made</i> impossible by the compiler. The &quot;everything is cancellable&quot; rabbit hole is infinite and is not worth pursuing. Eventually the Rust core team will be inspecting CPU microcode and its bugs, or what&#x27;s the endgame exactly? So let&#x27;s not go there, I say.<p>I know that Rust does not have a runtime and it does not have a spec but I think the questions posed in the article hint at the need for either -- or even both at the same time (i.e. &quot;make a spec for the third party runtime implementors&quot;).<p>I am not saying &quot;imitate Golang or Erlang&quot;. I am saying: &quot;just pick a side already&quot;.<p>On a more intuitive level: to me it feels like Rust tries to be everything for everyone, and I think many of us know that will never work.<p>Choose. Commit. Double down. Make it work. Golang and Erlang did. Rust can do it as well.
评论 #39499131 未加载
评论 #39499827 未加载
u320about 1 year ago
Reading about async Rust is like reading about a large complicated infrastructure project that keeps getting delays and cost overruns. Rust will end up spending a significant part of its complexity budget on async alone. I wonder if it&#x27;s worth it, for a problem that gets <i>significantly</i> easier if you are prepared to be just a bit more wasteful (allocations, memory, etc). Compare with Ocaml or Haskell for instance.
评论 #39499832 未加载
评论 #39499548 未加载
评论 #39499847 未加载
评论 #39499831 未加载
评论 #39499631 未加载
评论 #39504862 未加载
评论 #39499658 未加载
评论 #39499578 未加载
评论 #39499639 未加载
georgelyonabout 1 year ago
I’ve been following a similar issue in Swift (which is informed by some learnings from the Rust side of things). Here is a link to the latest language complexity resulting from this: <a href="https:&#x2F;&#x2F;forums.swift.org&#x2F;t&#x2F;sub-pitch-task-local-values-in-isolated-synchronous-deinit-and-async-deinit&#x2F;70060&#x2F;5" rel="nofollow">https:&#x2F;&#x2F;forums.swift.org&#x2F;t&#x2F;sub-pitch-task-local-values-in-is...</a><p>There are a number of other proposals linked to this issue that can be referenced from that thread. I hope there is a next generation async model for future languages that is truly simple, because this all makes me think footguns are endemic to the current approach (which is broadly the same in Rust and Swift).
feverzsjabout 1 year ago
Seems java&#x27;s virtual thread is the only sane async model out there.
评论 #39499164 未加载
评论 #39499567 未加载
lordmauveabout 1 year ago
&gt; I would be interested in examples of code that users believe require cancellation-specific async code, though.<p>This happens all the time. For example, cancellation in the middle of sending a HTTP request. The connection is now unusable and must be closed. Without cancellation the connection returns to a state where it can be used and is re-added to a pool.
PoignardAzurabout 1 year ago
&gt; <i>On a UNIX system, the file is closed in the call to drop by calling close(2). What happens if that call returns an error? The standard library ignores it. This is partly because there’s not much you can do to respond to close(2) erroring, as a comment in the standard library elucidates</i><p>Note that this is true for UNIX file descriptors, but not for C++ streams: an error when closing may indicate that the stream you closed had some buffered data it failed to flush (for any of the reasons that a failed write might come from).<p>In that case, you sometimes <i>do</i> want to take a different codepath to avoid data loss; eg, if your database does &quot;copy file X to new file Y, then remove X&quot;, if closing&#x2F;flushing Y fails then you <i>absolutely</i> want to abort removing X.<p>In the case of Rust code, the method you want is `File::sync_all`, which returns a Result for this exact purpose.
hardwaresoftonabout 1 year ago
In the meantime I actually wrote a create that hacks around this problem:<p><a href="https:&#x2F;&#x2F;crates.io&#x2F;crates&#x2F;async-dropper" rel="nofollow">https:&#x2F;&#x2F;crates.io&#x2F;crates&#x2F;async-dropper</a>
asabilabout 1 year ago
&gt; I don’t have an example of fully non-cooperative cancellation available off the top of my head.<p>That would be Erlang.
ggreg84about 1 year ago
Asynchronous clean-up is a solved problem in C++ senders &amp; receivers.<p>I wonder what&#x27;s so different about rust that they can&#x27;t solve it in the same way.
38about 1 year ago
&gt; I can write all these posts and tell you with a straight face there’s no tradeoff because appeasing the borrow checker is NBD. I never think about appeasing the borrow checker when I write Rust.<p>Guy is in a bubble. He doesn&#x27;t realize that 99% of rust programmers don&#x27;t have the experience he does.
评论 #39498563 未加载
评论 #39499208 未加载
评论 #39500030 未加载