@@ -5,9 +5,10 @@ use solana_sdk::{instruction::InstructionError, signer::Signer, transaction::Tra
55use solana_transaction_utils:: { error:: Error as TransactionQueueError , queue:: TransactionTask } ;
66use tokio_graceful_shutdown:: SubsystemHandle ;
77use tracing:: { debug, info} ;
8- use tuktuk_program:: TaskQueueV0 ;
9- use tuktuk_sdk:: compiled_transaction:: {
10- next_available_task_ids_excluding_in_progress, run_ix_with_free_tasks,
8+ use tuktuk_program:: { TaskQueueV0 , TaskV0 } ;
9+ use tuktuk_sdk:: {
10+ client:: GetAnchorAccount ,
11+ compiled_transaction:: { next_available_task_ids_excluding_in_progress, run_ix_with_free_tasks} ,
1112} ;
1213
1314use crate :: {
@@ -271,6 +272,23 @@ impl TimedTask {
271272 ) ) if code == 3012 && ctx. rpc_client . get_account ( & self . task_key ) . await . is_err ( ) => {
272273 info ! ( ?self . task_key, "task not found, removing from queue" ) ;
273274 }
275+ // Handle task not ready
276+ // There's a race condition where the task was already completed and replaced with a new one,
277+ // yet we're still trying to process the old task.
278+ TransactionQueueError :: TransactionError ( TransactionError :: InstructionError (
279+ _,
280+ InstructionError :: Custom ( code) ,
281+ ) ) if code == 6005
282+ && ctx
283+ . rpc_client
284+ . anchor_account :: < TaskV0 > ( & self . task_key )
285+ . await
286+ . ok ( )
287+ . flatten ( )
288+ . is_some_and ( |acc| acc. queued_at != self . task . queued_at ) =>
289+ {
290+ info ! ( ?self . task_key, "task was already replaced, skipping" ) ;
291+ }
274292 TransactionQueueError :: RawTransactionError ( _)
275293 | TransactionQueueError :: SimulatedTransactionError ( _)
276294 | TransactionQueueError :: TransactionError ( _)
0 commit comments