@@ -1256,6 +1256,12 @@ SaveSlotToPath(ReplicationSlot *slot, const char *dir, int elevel)
1256
1256
fd = OpenTransientFile (tmppath , O_CREAT | O_EXCL | O_WRONLY | PG_BINARY );
1257
1257
if (fd < 0 )
1258
1258
{
1259
+ /*
1260
+ * If not an ERROR, then release the lock before returning. In case
1261
+ * of an ERROR, the error recovery path automatically releases the
1262
+ * lock, but no harm in explicitly releasing even in that case.
1263
+ */
1264
+ LWLockRelease (& slot -> io_in_progress_lock );
1259
1265
ereport (elevel ,
1260
1266
(errcode_for_file_access (),
1261
1267
errmsg ("could not create file \"%s\": %m" ,
@@ -1287,6 +1293,7 @@ SaveSlotToPath(ReplicationSlot *slot, const char *dir, int elevel)
1287
1293
1288
1294
pgstat_report_wait_end ();
1289
1295
CloseTransientFile (fd );
1296
+ LWLockRelease (& slot -> io_in_progress_lock );
1290
1297
1291
1298
/* if write didn't set errno, assume problem is no disk space */
1292
1299
errno = save_errno ? save_errno : ENOSPC ;
@@ -1306,6 +1313,7 @@ SaveSlotToPath(ReplicationSlot *slot, const char *dir, int elevel)
1306
1313
1307
1314
pgstat_report_wait_end ();
1308
1315
CloseTransientFile (fd );
1316
+ LWLockRelease (& slot -> io_in_progress_lock );
1309
1317
errno = save_errno ;
1310
1318
ereport (elevel ,
1311
1319
(errcode_for_file_access (),
@@ -1317,6 +1325,7 @@ SaveSlotToPath(ReplicationSlot *slot, const char *dir, int elevel)
1317
1325
1318
1326
if (CloseTransientFile (fd ) != 0 )
1319
1327
{
1328
+ LWLockRelease (& slot -> io_in_progress_lock );
1320
1329
ereport (elevel ,
1321
1330
(errcode_for_file_access (),
1322
1331
errmsg ("could not close file \"%s\": %m" ,
@@ -1327,6 +1336,7 @@ SaveSlotToPath(ReplicationSlot *slot, const char *dir, int elevel)
1327
1336
/* rename to permanent file, fsync file and directory */
1328
1337
if (rename (tmppath , path ) != 0 )
1329
1338
{
1339
+ LWLockRelease (& slot -> io_in_progress_lock );
1330
1340
ereport (elevel ,
1331
1341
(errcode_for_file_access (),
1332
1342
errmsg ("could not rename file \"%s\" to \"%s\": %m" ,
0 commit comments