@@ -158,6 +158,16 @@ void LogDev::stop() {
158158 // trigger a new flush to make sure all pending writes are flushed
159159 flush_under_guard ();
160160
161+ {
162+ std::unique_lock lg = flush_guard ();
163+ // wait again for any callbacks issued by new flush
164+ while (m_pending_callback.load () > 0 ) {
165+ THIS_LOGDEV_LOG (INFO, " Waiting for new pending callbacks to complete, pending callbacks {}" ,
166+ m_pending_callback.load ());
167+ std::this_thread::sleep_for (std::chrono::milliseconds{1000 });
168+ }
169+ }
170+
161171 // after we call stop, we need to do any pending device truncations
162172 truncate ();
163173 m_id_logstore_map.clear ();
@@ -583,10 +593,12 @@ void LogDev::on_flush_completion(LogGroup* lg) {
583593
584594 // since we support out-of-order lsn write, so no need to guarantee the order of logstore write completion
585595 for (auto const & [idx, req] : req_map) {
596+ m_pending_callback++;
586597 auto callback_lambda = [this , dev_offset, idx, req]() {
587598 auto ld_key = logdev_key{idx, dev_offset};
588599 auto comp_cb = req->log_store ->get_comp_cb ();
589600 (req->cb ) ? req->cb (req, ld_key) : comp_cb (req, ld_key);
601+ m_pending_callback--;
590602 };
591603
592604 // if we do not have repl_service, we run the callback in a random worker for the case of log store UT, where
0 commit comments