4 ms·
doesn't rust have raii?
by nofriend 1y ago
doesn't rust have raii?
- sunshowers 1y agoIt does, but you can only run synchronous code on drop. This is what "async drop" is supposed to handle — things like issuing ROLLBACK statements to the database on cancellation. It also wouldn't help when you have no valid state to restore to, as in the mutex example in the post.
- 0x1ceb00da 1y agotokio-postgres handles this by just dispatching the "ROLLBACK" command in impl Drop and ignoring the response. https://github.com/rust-postgres/rust-postgres/blob/a7a49a90734c05664ed56356b61aa937cc2a6e6b/tokio-postgres/src/client.rs#L606 https://github.com/rust-postgres/rust-postgres/blob/a7a49a90... Is this not enough? What could go wrong? If the network connection dies or the task is cancelled, I'm assuming the database server cleans up the connection state and does a rollback automatically. And adding async Drop will probably add a whole new set of footguns.
- _davide_ 1y ago> What could go wrong? LoL, an insane amount of things. TCP connections are an illusion of safely, for the purpose of database commits use UDP packets as a model instead, it'll be much closer to reality.
- 0x1ceb00da 1y ago> an insane amount of things List a couple > TCP connections are an illusion of safely Why?
- deleted 1y ago[deleted]