Skip to content

Deadlock might happens when database is shutting down with internal worker attachments exists. #8390

@hvlad

Description

@hvlad

Deadlock between WorkerAttachment::shutdownDbb() and WorkerStableAttachment::doOnIdleTimer() due to wrong mutexes lock order, see stacks below:

One thread enters m_mapMutex (by WorkerAttachment::shutdownDbb()) and waits for StableAttachmentPart::mainSync:

engine13.dll!Firebird::Mutex::enter(const char * aReason=0x00007ff9c779e140) Line 95
	at src\common\classes\locks.h(95)
engine13.dll!Jrd::StableAttachmentPart::Sync::enter(const char * aReason=0x00007ff9c779e140) Line 231
	at src\jrd\Attachment.h(231)
engine13.dll!Firebird::RaiiLockGuard<Jrd::StableAttachmentPart::Sync>::RaiiLockGuard<Jrd::StableAttachmentPart::Sync>(Jrd::StableAttachmentPart::Sync & aLock={...}, const char * aReason=0x00007ff9c779e140) Line 331
	at src\common\classes\locks.h(331)
engine13.dll!Jrd::WorkerStableAttachment::fini() Line 113
	at src\jrd\WorkerAttachment.cpp(113)
engine13.dll!Jrd::WorkerAttachment::doDetach(Firebird::CheckStatusWrapper * status=0x000000000014df78, Jrd::StableAttachmentPart * sAtt=0x0000000004593110) Line 475
	at src\jrd\WorkerAttachment.cpp(475)
engine13.dll!Jrd::WorkerAttachment::clear(bool checkRefs=false) Line 402
	at src\jrd\WorkerAttachment.cpp(402)
engine13.dll!Jrd::WorkerAttachment::shutdownDbb(Jrd::Database * dbb=0x00000000008052d0) Line 241
	at src\jrd\WorkerAttachment.cpp(241)
engine13.dll!JRD_shutdown_database(Jrd::Database * dbb=0x00000000008052d0, const unsigned int flags=3) Line 7963
	at src\jrd\jrd.cpp(7963)
engine13.dll!purge_attachment(Jrd::thread_db * tdbb=0x000000000014eb80, Jrd::StableAttachmentPart * sAtt=0x000000000429f9a0, unsigned int flags=2) Line 8449
	at src\jrd\jrd.cpp(8449)
engine13.dll!Jrd::JAttachment::freeEngineData(Firebird::CheckStatusWrapper * user_status=0x000000000014ee58, bool forceFree=false) Line 3349
	at src\jrd\jrd.cpp(3349)
engine13.dll!Jrd::JAttachment::internalDetach(Firebird::CheckStatusWrapper * user_status=0x000000000014ee58) Line 3286
	at src\jrd\jrd.cpp(3286)
engine13.dll!Jrd::JAttachment::detach(Firebird::CheckStatusWrapper * user_status=0x000000000014ee58) Line 3298
	at src\jrd\jrd.cpp(3298)

Another thread enters StableAttachmentPart::mainSync (by WorkerAttachment::detachIdle) and waits for m_mapMutex:

engine13.dll!Firebird::Mutex::enter(const char * aReason=0x00007ff9c779e170) Line 95
	at src\common\classes\locks.h(95)
engine13.dll!Firebird::RaiiLockGuard<Firebird::Mutex>::RaiiLockGuard<Firebird::Mutex>(Firebird::Mutex & aLock={...}, const char * aReason=0x00007ff9c779e170) Line 331
	at src\common\classes\locks.h(331)
engine13.dll!Jrd::WorkerAttachment::getByName(const Firebird::StringBase<Firebird::PathNameComparator> & dbname={...}) Line 188
	at src\jrd\WorkerAttachment.cpp(188)
engine13.dll!Jrd::WorkerAttachment::detachIdle(Jrd::StableAttachmentPart * sAtt=0x0000000004593110) Line 416
	at src\jrd\WorkerAttachment.cpp(416)
engine13.dll!Jrd::WorkerStableAttachment::doOnIdleTimer(Firebird::TimerImpl * timer=0x0000000004593b30) Line 106
	at src\jrd\WorkerAttachment.cpp(106)
engine13.dll!Jrd::StableAttachmentPart::onIdleTimer(Firebird::TimerImpl * timer=0x0000000004593b30) Line 377
	at src\jrd\Attachment.h(377)
[External Code]
engine13.dll!Firebird::TimerImpl::handler() Line 64
	at src\common\classes\TimerImpl.cpp(64)
engine13.dll!Firebird::ITimerBaseImpl<Firebird::TimerImpl,Firebird::CheckStatusWrapper,Firebird::IReferenceCountedImpl<Firebird::TimerImpl,Firebird::CheckStatusWrapper,Firebird::Inherit<Firebird::IVersionedImpl<Firebird::TimerImpl,Firebird::CheckStatusWrapper,Firebird::Inherit<Firebird::ITimer>>>>>::cloophandlerDispatcher(Firebird::ITimer * self=0x0000000004593b38) Line 15722
	at src\include\firebird\IdlFbInterfaces.h(15722)
fbclient.dll!Firebird::ITimer::handler() Line 4553
	at src\include\firebird\IdlFbInterfaces.h(4553)
fbclient.dll!Why::`anonymous namespace'::TimerEntry::timeThread(void * __formal=0x0000000000000000) Line 286
	at src\yvalve\MasterImplementation.cpp(286)
fbclient.dll!`anonymous namespace'::ThreadArgs::run() Line 78
	at src\common\ThreadStart.cpp(78)

Only SuperServer is affected.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions