Skip to content

Commit 2b6d031

Browse files
NoremosArtyom Abakumov
andauthored
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>
1 parent f59905f commit 2b6d031

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/jrd/trace/TraceConfigStorage.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -470,15 +470,20 @@ void ConfigStorage::compact()
470470
ULONG check_used, check_size;
471471
check_used = check_size = sizeof(TraceCSHeader);
472472

473+
// Track undeleted slots from dead processes
474+
Firebird::SortedArray<ULONG, InlineStorage<ULONG, 16>> deadProcesses;
475+
473476
// collect used slots, sort them by offset
474477
for (TraceCSHeader::Slot* slot = header->slots; slot < header->slots + header->slots_cnt; slot++)
475478
{
476479
if (slot->used && slot->ses_pid != pid &&
477480
((slot->ses_flags & trs_system) == 0) && // System sessions are shared for multiple connections so they may live without the original process
478481
!ISC_check_process_existence(slot->ses_pid))
479482
{
480-
fb_assert(header->cnt_uses != 0);
481-
header->cnt_uses--; // Process that created trace session disappeared, count it out
483+
// A SUPER server may shut down, but its Storage shared memory continues to live due to an embedded user session.
484+
// The process might allocate multiple slots, so count them carefully.
485+
deadProcesses.add(slot->ses_pid);
486+
482487
markDeleted(slot);
483488
}
484489

@@ -491,6 +496,11 @@ void ConfigStorage::compact()
491496
data.add(item);
492497
}
493498

499+
// Process that created storages disappeared, count it out
500+
fb_assert(header->cnt_uses > deadProcesses.getCount());
501+
header->cnt_uses -= deadProcesses.getCount();
502+
deadProcesses.clear();
503+
494504
fb_assert(check_used == header->mem_used);
495505
fb_assert(check_size == header->mem_offset);
496506

0 commit comments

Comments
 (0)