This is an automated email from the ASF dual-hosted git repository. maxyang pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/cloudberry.git
commit 73da0f32f3860cb9ca128221761bc49929586deb Author: dh-cloud <[email protected]> AuthorDate: Wed Jul 20 09:02:52 2022 +0800 Remove palloc() call in ResWaitOnLock (#13701) If palloc() failed in ResWaitOnLock due to OOM, it will trigger a PANIC "Waiting on lock already held" because partitionLock is not released correctly. The first attempt is to add a try/catch surrounding for this palloc() call, and release the partitionLock before rethrowing error. But it is not good as ResIncrementRemove is not called. So use local char new_status[160], length 160 is enough. ---- Steps to reproduce: Add a fault at the palloc() position: SIMPLE_FAULT_INJECTOR("reslock_acquire_before_wait"); ```sql -- superuser: -- test user session 1: > SELECT pg_sleep(120); -- test user session 2: > SELECT version(); PANIC: Waiting on lock already held! (lwlock.c:668) server closed the connection unexpectedly ``` --- src/backend/utils/resscheduler/resqueue.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/backend/utils/resscheduler/resqueue.c b/src/backend/utils/resscheduler/resqueue.c index fa3c985b89..7ee6afbe6f 100644 --- a/src/backend/utils/resscheduler/resqueue.c +++ b/src/backend/utils/resscheduler/resqueue.c @@ -1085,18 +1085,21 @@ ResWaitOnLock(LOCALLOCK *locallock, ResourceOwner owner, ResPortalIncrement *inc { uint32 hashcode = locallock->hashcode; LWLockId partitionLock = LockHashPartitionLock(hashcode); + char new_status[160]; const char *old_status; - char *new_status = NULL; int len; /* Report change to waiting status */ if (update_process_title) { + /* We should avoid using palloc() here */ old_status = get_real_act_ps_display(&len); - new_status = (char *) palloc(len + 8 + 1); - memcpy(new_status, old_status, len); - strcpy(new_status + len, " queuing"); - set_ps_display(new_status); /* truncate off " queuing" */ + len = Min(len, sizeof(new_status) - 9); + snprintf(new_status, sizeof(new_status), "%.*s queuing", + len, old_status); + set_ps_display(new_status); + + /* Truncate off " queuing" */ new_status[len] = '\0'; } @@ -1123,7 +1126,6 @@ ResWaitOnLock(LOCALLOCK *locallock, ResourceOwner owner, ResPortalIncrement *inc if (update_process_title) { set_ps_display(new_status); - pfree(new_status); } return; --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
