File tree Expand file tree Collapse file tree 1 file changed +8
-14
lines changed Expand file tree Collapse file tree 1 file changed +8
-14
lines changed Original file line number Diff line number Diff line change @@ -172,23 +172,17 @@ impl Runner {
172
172
// TODO: Replace with flatten() once that stabilizes
173
173
. and_then ( std:: convert:: identity) ;
174
174
175
+ // If the job panics it could leave the connection inside an inner transaction(s).
176
+ // Attempt to roll those back so we can mark the job as failed, but if the rollback
177
+ // fails then there isn't much we can do at this point so return early. `r2d2` will
178
+ // detect the bad state and drop it from the pool.
175
179
loop {
176
- let depth = get_transaction_depth ( conn) ;
177
- if depth == Ok ( initial_depth) {
180
+ let depth = get_transaction_depth ( conn) ? ;
181
+ if depth == initial_depth {
178
182
break ;
179
183
}
180
184
warn ! ( "Rolling back a transaction due to a panic in a background task" ) ;
181
- match <AnsiTransactionManager as TransactionManager < PgConnection > >:: rollback_transaction ( conn)
182
- {
183
- Ok ( _) => ( ) ,
184
- Err ( e) => {
185
- error ! ( "Leaking a thread and database connection because of an error while rolling back transaction: {e}" ) ;
186
- loop {
187
- std:: thread:: sleep ( Duration :: from_secs ( 24 * 60 * 60 ) ) ;
188
- error ! ( "How am I still alive?" ) ;
189
- }
190
- }
191
- }
185
+ AnsiTransactionManager :: rollback_transaction ( conn) ?;
192
186
}
193
187
194
188
match result {
@@ -246,7 +240,7 @@ impl Runner {
246
240
}
247
241
248
242
fn get_transaction_depth ( conn : & mut PgConnection ) -> QueryResult < u32 > {
249
- let transaction_manager = < AnsiTransactionManager as TransactionManager < PgConnection > > :: transaction_manager_status_mut ( conn) ;
243
+ let transaction_manager = AnsiTransactionManager :: transaction_manager_status_mut ( conn) ;
250
244
Ok ( transaction_manager
251
245
. transaction_depth ( ) ?
252
246
. map ( u32:: from)
You can’t perform that action at this time.
0 commit comments