Closed tisonkun closed 1 month ago
Since I use pool.begin to get this Transaction, I change the type sig to Transaction<'static, Postgres>
and get it fixed.
However, it looks like a rust compiler bug that I must move the txn into the closure but it reports that the txn escapes ..
What is common_runtime::meta_runtime().spawn(...)
?
I am assuming you are using tokio::task::spawn
`
=> that future requires a 'static lifetime. See the docs for an explaination why and how to deal with this.
Lets back off: Why do you want to use a for part of the transaction? That seems somewhat strange to me..
that future requires a 'static lifetime
This seems the answer. Thank you!
Why do you want to use a for part of the transaction?
I have a meta service to interact with PG in a transaction context. Previously, I pass a closure as an effective "stored process" to process data read from txn. But later I encounter some subtle closure issues (mainly about error handling, that I'd return an error to the parent of parent context or things like that) (closure is complex in Rust, isn't it?).
So I try to read the data within txn and return both the data and the txn, and then pass back the txn with second part's input to continue the transaction, as shown in the fn sig above.
What does the "meta service" do preciciely?
The context you gave does not answer why you need to spawn a new task on your runtime inside of the Transaction<'_, Postgres>
.
=> not having that code is likely better and solves your problem as far as you have explained.
@CommanderStorm I agree that context is lacking.
My question is answered anyway and thanks for your time. Perhaps I can share my user story once the code above is open sourced (hopefully in a few weeks).
Bug Description
Create a transaction, return it outside and later move back can cause lifetime checker suck.
Minimal Reproduction
reports:
Info
rustc --version
: rustc 1.82.0-nightly (28a58f2fa 2024-07-31)