catfile: Fix deadlock between reading a new object and accessing it
When we read in a new object via ReadObject()
, then we must perform an
I/O operation to learn about its header. This operation is currently
done under the currentObjectLock()
, but this can easily cause us to
deadlock when the I/O operation stalls. Consequentially, it's impossible
to access this object now anymore by other callers. Most importantly,
this means that both close()
and isDirty()
are blocked from making
any progress. But because those are used to determine whether processes
of the request queue should be killed in the first place we are now in a
deadlock-state.
Fix this issue by splitting up the lock into a read-lock for the current
object whose scope is a lot more fine-grained and only used when we
access the field or when we write to it. The second atomic lock is used
to only lock writing access across the whole lifetime of ReadObject()
so that no other caller can call it at the same time.
Changelog: fixed
Part of #4253 (closed)