Skip to content

Commit f36a104

Browse files
committed
Drop slot's LWLock before returning from SaveSlotToPath()
When SaveSlotToPath() is called with elevel=LOG, the early exits didn't release the slot's io_in_progress_lock. This could result in a walsender being stuck on the lock forever. A possible way to get into this situation is if the offending code paths are triggered in a low disk space situation. Author: Pavan Deolasee <pavan.deolasee@2ndquadrant.com> Reported-by: Craig Ringer <craig@2ndquadrant.com> Discussion: https://www.postgresql.org/message-id/flat/56a138c5-de61-f553-7e8f-6789296de785%402ndquadrant.com
1 parent 2060999 commit f36a104

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/backend/replication/slot.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1251,6 +1251,12 @@ SaveSlotToPath(ReplicationSlot *slot, const char *dir, int elevel)
12511251
S_IRUSR | S_IWUSR);
12521252
if (fd < 0)
12531253
{
1254+
/*
1255+
* If not an ERROR, then release the lock before returning. In case
1256+
* of an ERROR, the error recovery path automatically releases the
1257+
* lock, but no harm in explicitly releasing even in that case.
1258+
*/
1259+
LWLockRelease(&slot->io_in_progress_lock);
12541260
ereport(elevel,
12551261
(errcode_for_file_access(),
12561262
errmsg("could not create file \"%s\": %m",
@@ -1282,6 +1288,7 @@ SaveSlotToPath(ReplicationSlot *slot, const char *dir, int elevel)
12821288

12831289
pgstat_report_wait_end();
12841290
CloseTransientFile(fd);
1291+
LWLockRelease(&slot->io_in_progress_lock);
12851292

12861293
/* if write didn't set errno, assume problem is no disk space */
12871294
errno = save_errno ? save_errno : ENOSPC;
@@ -1301,6 +1308,7 @@ SaveSlotToPath(ReplicationSlot *slot, const char *dir, int elevel)
13011308

13021309
pgstat_report_wait_end();
13031310
CloseTransientFile(fd);
1311+
LWLockRelease(&slot->io_in_progress_lock);
13041312
errno = save_errno;
13051313
ereport(elevel,
13061314
(errcode_for_file_access(),
@@ -1315,6 +1323,7 @@ SaveSlotToPath(ReplicationSlot *slot, const char *dir, int elevel)
13151323
/* rename to permanent file, fsync file and directory */
13161324
if (rename(tmppath, path) != 0)
13171325
{
1326+
LWLockRelease(&slot->io_in_progress_lock);
13181327
ereport(elevel,
13191328
(errcode_for_file_access(),
13201329
errmsg("could not rename file \"%s\" to \"%s\": %m",

0 commit comments

Comments
 (0)