Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
vici: Don't lock connection in write mode when enabling on_write() ca…
…llback This should prevent a deadlock that could previously be caused when a control-log event was raised. The deadlock looked something like this: * Thread A holds the read lock on bus_t and raises the control-log event. This requires acquiring the connection entry in write mode to queue the outgoing message. If it is already held by another thread, this blocks on a condvar. * Thread B is registering the on_write() callback on the same connection's stream due to a previous log message. Before, the code acquired the entry in write mode, thus, blocking thread A. To remove/add the stream the mutex in watcher_t needs to be acquired. * Thread C is in watcher_t's watch() and holds the mutex while logging on level 2 or 3. The latter requires the read lock on bus_t, which should usually be acquirable unless writers are waiting on the lock and the implementation currently blocks new readers. * Thread D is removing a logger from the bus (e.g. after an initiate() call) and is waiting to acquire the write lock on bus_t and thereby blocking thread C. With this change, thread B should not block thread A anymore. So thread D and thread C should eventually be able to proceed as well. Thread A could be held up a bit if there is a thread already sending messages for the same connection, but that should only cause a delay, no deadlock, as on_write() and do_write() don't log anything while keeping the entry locked in write mode.
- Loading branch information