bareos: master 20682c92

Author Committer Branch Timestamp Parent
Sebastian Sura Bareos Bot master 2024-03-07 09:35 master 689cc224 Pending
Changeset stored: fix jcr->authenticate data race

The condition variable is not used correctly:

// reader
1| while (!unprotected) {
2| wait(cond_var)
    }
// writer

3| unprotected = true;
4| signal(cond_var)

The execution order 1->3->4->2 will cause a deadlock. This is why the
wait command takes a mutex: Everything that might change the
condition to be true needs to lock the mutex, this way we can ensure
that we either see the updated value or the wait sees the signal.

Since jcr->authenticate is used all over the place in a lot of
different situations, this problem could not be easily fixed by just
protecting that variable (we do not want weird deadlocks to happen
after all).

We just do not rely on jcr->authenticate anymore when it comes to
waiting on job start. Instead we have a single, properly protected
bool `client_available` that we can wait on.
This bool obviously needs to be set by whoever authenticates the FD/SD
connection, otherwise the job will deadlock. But at least that is
easily fixable.
mod - core/src/stored/dir_cmd.cc Diff File
mod - core/src/stored/fd_cmds.cc Diff File
mod - core/src/stored/job.cc Diff File
mod - core/src/stored/ndmp_tape.cc Diff File
mod - core/src/stored/sd_cmds.cc Diff File
mod - core/src/stored/stored.cc Diff File
mod - core/src/stored/stored_jcr_impl.h Diff File