Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
hvlad opened this issue Jan 15, 2025 · 0 comments

Comments

@hvlad
Copy link
Member

hvlad commented Jan 15, 2025

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant