Skip to content

Commit e6f52a7

Browse files
maksm90akorotkov
authored andcommitted
Fix another issue with collector infinite loop.
In some rare cases collector acquires own exclusive lock but doesn't release it. I suppose that after acquiring but before releasing of lock there was some exception that was interrupted somewhere above but collector lock releasing was lost. This commit adds try-catch block surrounding critical lock section to release lock anyway
1 parent d77c9e2 commit e6f52a7

File tree

1 file changed

+45
-35
lines changed

1 file changed

+45
-35
lines changed

collector.c

Lines changed: 45 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -436,47 +436,57 @@ collector_main(Datum main_arg)
436436
LockAcquire(&tag, ExclusiveLock, false, false);
437437
collector_hdr->request = NO_REQUEST;
438438

439-
if (request == HISTORY_REQUEST || request == PROFILE_REQUEST)
439+
PG_TRY();
440440
{
441-
shm_mq_result mq_result;
442-
443-
/* Send history or profile */
444-
shm_mq_set_sender(collector_mq, MyProc);
445-
mqh = shm_mq_attach(collector_mq, NULL, NULL);
446-
mq_result = shm_mq_wait_for_attach(mqh);
447-
switch (mq_result)
441+
if (request == HISTORY_REQUEST || request == PROFILE_REQUEST)
442+
{
443+
shm_mq_result mq_result;
444+
445+
/* Send history or profile */
446+
shm_mq_set_sender(collector_mq, MyProc);
447+
mqh = shm_mq_attach(collector_mq, NULL, NULL);
448+
mq_result = shm_mq_wait_for_attach(mqh);
449+
switch (mq_result)
450+
{
451+
case SHM_MQ_SUCCESS:
452+
switch (request)
453+
{
454+
case HISTORY_REQUEST:
455+
send_history(&observations, mqh);
456+
break;
457+
case PROFILE_REQUEST:
458+
send_profile(profile_hash, mqh);
459+
break;
460+
default:
461+
AssertState(false);
462+
}
463+
break;
464+
case SHM_MQ_DETACHED:
465+
ereport(WARNING,
466+
(errmsg("pg_wait_sampling collector: "
467+
"receiver of message queue have been "
468+
"detached")));
469+
break;
470+
default:
471+
AssertState(false);
472+
}
473+
shm_mq_detach_compat(mqh, collector_mq);
474+
}
475+
else if (request == PROFILE_RESET)
448476
{
449-
case SHM_MQ_SUCCESS:
450-
switch (request)
451-
{
452-
case HISTORY_REQUEST:
453-
send_history(&observations, mqh);
454-
break;
455-
case PROFILE_REQUEST:
456-
send_profile(profile_hash, mqh);
457-
break;
458-
default:
459-
AssertState(false);
460-
}
461-
break;
462-
case SHM_MQ_DETACHED:
463-
ereport(WARNING,
464-
(errmsg("pg_wait_sampling collector: "
465-
"receiver of message queue have been "
466-
"detached")));
467-
break;
468-
default:
469-
AssertState(false);
477+
/* Reset profile hash */
478+
hash_destroy(profile_hash);
479+
profile_hash = make_profile_hash();
470480
}
471-
shm_mq_detach_compat(mqh, collector_mq);
481+
482+
LockRelease(&tag, ExclusiveLock, false);
472483
}
473-
else if (request == PROFILE_RESET)
484+
PG_CATCH();
474485
{
475-
/* Reset profile hash */
476-
hash_destroy(profile_hash);
477-
profile_hash = make_profile_hash();
486+
LockRelease(&tag, ExclusiveLock, false);
487+
PG_RE_THROW();
478488
}
479-
LockRelease(&tag, ExclusiveLock, false);
489+
PG_END_TRY();
480490
}
481491
}
482492

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy