8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-23 10:43:03 +01:00

Fix one of the reason for AV in the engine (see CORE-4680, test by Pavel Zotov at 18 Nov 2015).

The race when gone attachment released database object while another attachment is initialized and uses same database object.
Could happens with shared cache (former SS) only.
This commit is contained in:
hvlad 2015-11-20 10:17:54 +00:00
parent fb7f56077c
commit a6d615c0cd
2 changed files with 10 additions and 4 deletions

View File

@ -381,11 +381,11 @@ bool CCH_exclusive_attachment(thread_db* tdbb, USHORT level, SSHORT wait_flag, S
SET_TDBB(tdbb);
Database* const dbb = tdbb->getDatabase();
Sync dsGuard(&dbb->dbb_sync, "CCH_exclusive_attachment");
Sync dsGuard(&dbb->dbb_sync, FB_FUNCTION);
const bool exLock = dbb->dbb_sync.ourExclusiveLock();
if (!exLock)
dsGuard.lock(SYNC_SHARED);
dsGuard.lock(level != LCK_none ? SYNC_EXCLUSIVE : SYNC_SHARED);
else
fb_assert(exGuard);
@ -413,6 +413,9 @@ bool CCH_exclusive_attachment(thread_db* tdbb, USHORT level, SSHORT wait_flag, S
}
attachment->att_next = dbb->dbb_attachments;
dbb->dbb_attachments = attachment;
if (!exLock)
dsGuard.downgrade(SYNC_SHARED);
}
for (SLONG remaining = timeout; remaining >= 0; remaining -= CCH_EXCLUSIVE_RETRY_INTERVAL)

View File

@ -6550,8 +6550,11 @@ bool JRD_shutdown_database(Database* dbb, const unsigned flags)
return false;
}
if (dbb->dbb_attachments)
return false;
{
SyncLockGuard dsGuard(&dbb->dbb_sync, SYNC_EXCLUSIVE, FB_FUNCTION);
if (dbb->dbb_attachments)
return false;
}
// Database linger
if ((flags & SHUT_DBB_LINGER) &&