Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit422952e

Browse files
committed
Allow DSM allocation to be interrupted.
Chris Travers reported that the startup process can repeatedly try tocancel a backend that is in a posix_fallocate()/EINTR loop and cause itto loop forever. Teach the retry loop to give up if an interrupt ispending. Don't actually check for interrupts in that loop though,because a non-local exit would skip some clean-up code in the caller.Back-patch to 9.4 where DSM was added (and posix_fallocate() was laterback-patched).Author: Chris TraversReviewed-by: Ildar Musin, Murat Kabilov, Oleksii KliukinTested-by: Oleksii KliukinDiscussion:https://postgr.es/m/CAN-RpxB-oeZve_J3SM_6%3DHXPmvEG%3DHX%2B9V9pi8g2YR7YW0rBBg%40mail.gmail.com
1 parent1d6fbc3 commit422952e

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

‎src/backend/storage/ipc/dsm_impl.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
*/
4848

4949
#include"postgres.h"
50+
#include"miscadmin.h"
5051

5152
#include<fcntl.h>
5253
#include<unistd.h>
@@ -330,6 +331,14 @@ dsm_impl_posix(dsm_op op, dsm_handle handle, Size request_size,
330331
shm_unlink(name);
331332
errno=save_errno;
332333

334+
/*
335+
* If we received a query cancel or termination signal, we will have
336+
* EINTR set here. If the caller said that errors are OK here, check
337+
* for interrupts immediately.
338+
*/
339+
if (errno==EINTR&&elevel >=ERROR)
340+
CHECK_FOR_INTERRUPTS();
341+
333342
ereport(elevel,
334343
(errcode_for_dynamic_shared_memory(),
335344
errmsg("could not resize shared memory segment \"%s\" to %zu bytes: %m",
@@ -419,11 +428,15 @@ dsm_impl_posix_resize(int fd, off_t size)
419428
#if defined(HAVE_POSIX_FALLOCATE)&& defined(__linux__)
420429
if (rc==0)
421430
{
422-
/* We may get interrupted, if so just retry. */
431+
/*
432+
* We may get interrupted. If so, just retry unless there is an
433+
* interrupt pending. This avoids the possibility of looping forever
434+
* if another backend is repeatedly trying to interrupt us.
435+
*/
423436
do
424437
{
425438
rc=posix_fallocate(fd,0,size);
426-
}while (rc==EINTR);
439+
}while (rc==EINTR&& !(ProcDiePending||QueryCancelPending));
427440

428441
/*
429442
* The caller expects errno to be set, but posix_fallocate() doesn't

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp