bug(replication): fix deadlock in cancle replication flow (#1007)

Signed-off-by: adi_holden <adi@dragonflydb.io>
This commit is contained in:
adiholden 2023-03-29 12:11:56 +03:00 committed by GitHub
parent 44c477142a
commit 0312b66244
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 15 additions and 20 deletions

View file

@ -25,11 +25,17 @@ uint64_t JournalStreamer::GetRecordCount() const {
}
void JournalStreamer::Cancel() {
Finalize(); // Finalize must be called before UnregisterOnChange because we first need to stop
// writing to buffer and notify the all the producers.
// Writing to journal holds mutex protecting change_cb_arr_, than the fiber can
// preemt when calling NotifyWritten and it will not run again till notified.
// UnregisterOnChange will try to lock the mutex therefor calling UnregisterOnChange
// before Finalize may cause deadlock.
journal_->UnregisterOnChange(journal_cb_id_);
Finalize();
if (write_fb_.IsJoinable())
if (write_fb_.IsJoinable()) {
write_fb_.Join();
}
}
void JournalStreamer::WriterFb(io::Sink* dest) {