8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-22 20:43:02 +01:00

Additinal fix for #8180: Make sure trace session slots will not break use counter (#8192)

* Count dead storages carefully

* Better class to track dead process

Also correct the description

---------

Co-authored-by: Artyom Abakumov <artyom.abakumov@red-soft.ru>
This commit is contained in:
Artyom Abakumov 2024-07-24 14:39:42 +03:00 committed by GitHub
parent f59905fc29
commit 2b6d031cd2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -470,6 +470,9 @@ void ConfigStorage::compact()
ULONG check_used, check_size; ULONG check_used, check_size;
check_used = check_size = sizeof(TraceCSHeader); check_used = check_size = sizeof(TraceCSHeader);
// Track undeleted slots from dead processes
Firebird::SortedArray<ULONG, InlineStorage<ULONG, 16>> deadProcesses;
// collect used slots, sort them by offset // collect used slots, sort them by offset
for (TraceCSHeader::Slot* slot = header->slots; slot < header->slots + header->slots_cnt; slot++) for (TraceCSHeader::Slot* slot = header->slots; slot < header->slots + header->slots_cnt; slot++)
{ {
@ -477,8 +480,10 @@ void ConfigStorage::compact()
((slot->ses_flags & trs_system) == 0) && // System sessions are shared for multiple connections so they may live without the original process ((slot->ses_flags & trs_system) == 0) && // System sessions are shared for multiple connections so they may live without the original process
!ISC_check_process_existence(slot->ses_pid)) !ISC_check_process_existence(slot->ses_pid))
{ {
fb_assert(header->cnt_uses != 0); // A SUPER server may shut down, but its Storage shared memory continues to live due to an embedded user session.
header->cnt_uses--; // Process that created trace session disappeared, count it out // The process might allocate multiple slots, so count them carefully.
deadProcesses.add(slot->ses_pid);
markDeleted(slot); markDeleted(slot);
} }
@ -491,6 +496,11 @@ void ConfigStorage::compact()
data.add(item); data.add(item);
} }
// Process that created storages disappeared, count it out
fb_assert(header->cnt_uses > deadProcesses.getCount());
header->cnt_uses -= deadProcesses.getCount();
deadProcesses.clear();
fb_assert(check_used == header->mem_used); fb_assert(check_used == header->mem_used);
fb_assert(check_size == header->mem_offset); fb_assert(check_size == header->mem_offset);