typedb-driver icon indicating copy to clipboard operation
typedb-driver copied to clipboard

Transaction 'on close' callback is not triggered

Open krishnangovindraj opened this issue 1 year ago • 0 comments

Description

A transaction 'on close' callback registered is not always called.

Environment

  1. TypeDB distribution: Core, but it's a driver side bug.
  2. TypeDB version: 2.25.7
  3. Environment: Mac/Linux
  4. Other details: Reproduced on C++ and rust drivers.

Reproducible Steps

Here is a modified rust integration test.

 let session = Arc::new(Session::new(databases.get(common::TEST_DATABASE).await?, Data).await?);
        let transaction = session.transaction(Read).await?;
        
        let was_called = Arc::new(AtomicBool::new(false));
        transaction.on_close({
            let session = session.clone();
            let was_called = was_called.clone();
            move |_| {
                was_called.store(true, Ordering::SeqCst);
                session.force_close().ok();
            }
        });
        transaction.force_close();
        
        let mut n = 10;
        while n > 0 {
            if was_called.load(Ordering::SeqCst) {
                break;
            }
            thread::sleep(time::Duration::from_millis(1000));
            n -= 1;
        }
        assert_eq!(true, was_called.load(Ordering::SeqCst));

Expected result

The assert would pass.

krishnangovindraj avatar Dec 12 '23 14:12 krishnangovindraj