Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6cb233f7 authored by Yun-Hao Chung's avatar Yun-Hao Chung Committed by Yun-hao Chung
Browse files

Floss: Add extra delay in cleanup before exit

In the final step of the current cleanup process, we are waiting for the
thread event to be disassociated, which is called after btif cleanup
finished. However, there are more cleanup functions needed to be done
after btif cleanup in |event_clean_up_stack|. These become undefined
behaviors since the process is going to be terminated by btadapterd.

This adds an extra delay to give the rest of the cleanup processes
some time to finish.

Bug: 304997914
Test: rmmod btusb to trigger sigterm and observe the extra delay
Test: mma -j
Tag: #floss
Flag: EXEMPT, Floss-only changes
Change-Id: Id049a4b5c1192aae2b9a71ee1a7c394c9398f1c2
parent 1ef1ee91
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -51,6 +51,8 @@ const STACK_TURN_OFF_TIMEOUT_MS: Duration = Duration::from_millis(4000);
const STACK_CLEANUP_TIMEOUT_MS: Duration = Duration::from_millis(1000);
// Time bt_stack_manager waits for cleanup profiles
const STACK_CLEANUP_PROFILES_TIMEOUT_MS: Duration = Duration::from_millis(100);
// Extra time to wait before terminating the process
const EXTRA_WAIT_BEFORE_KILL_MS: Duration = Duration::from_millis(1000);

const INIT_LOGGING_MAX_RETRY: u8 = 3;

@@ -307,6 +309,10 @@ extern "C" fn handle_sigterm(_signum: i32) {
            log::debug!("Waiting for stack to clean up for {:?}", STACK_CLEANUP_TIMEOUT_MS);
            let _ = notifier.thread_notify.wait_timeout(guard, STACK_CLEANUP_TIMEOUT_MS);
        }

        // Extra delay to give the rest of the cleanup processes some time to finish after
        // finishing btif cleanup.
        std::thread::sleep(EXTRA_WAIT_BEFORE_KILL_MS);
    }

    log::debug!("Sigterm completed");