Fix deadlock when querying comments or downtimes through livestatus

fixes #5332