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

Commit5d8a894

Browse files
committed
Cancel running query if it is detected that the connection to the client is
lost. The only way we detect that at the moment is when write() fails whenwe try to write to the socket.Florian Pflug with small changes by me, reviewed by Greg Jaskiewicz.
1 parentd5f23af commit5d8a894

File tree

4 files changed

+25
-1
lines changed

4 files changed

+25
-1
lines changed

‎src/backend/libpq/pqcomm.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1247,9 +1247,13 @@ internal_flush(void)
12471247

12481248
/*
12491249
* We drop the buffered data anyway so that processing can
1250-
* continue, even though we'll probably quit soon.
1250+
* continue, even though we'll probably quit soon. We also
1251+
* set a flag that'll cause the next CHECK_FOR_INTERRUPTS
1252+
* to terminate the connection.
12511253
*/
12521254
PqSendStart=PqSendPointer=0;
1255+
ClientConnectionLost=1;
1256+
InterruptPending=1;
12531257
returnEOF;
12541258
}
12551259

‎src/backend/tcop/postgres.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2823,6 +2823,18 @@ ProcessInterrupts(void)
28232823
(errcode(ERRCODE_ADMIN_SHUTDOWN),
28242824
errmsg("terminating connection due to administrator command")));
28252825
}
2826+
if (ClientConnectionLost)
2827+
{
2828+
QueryCancelPending= false;/* lost connection trumps QueryCancel */
2829+
ImmediateInterruptOK= false;/* not idle anymore */
2830+
DisableNotifyInterrupt();
2831+
DisableCatchupInterrupt();
2832+
/* don't send to client, we already know the connection to be dead. */
2833+
whereToSendOutput=DestNone;
2834+
ereport(FATAL,
2835+
(errcode(ERRCODE_CONNECTION_FAILURE),
2836+
errmsg("connection to client lost")));
2837+
}
28262838
if (QueryCancelPending)
28272839
{
28282840
QueryCancelPending= false;

‎src/backend/utils/init/globals.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ ProtocolVersion FrontendProtocol;
2929
volatileboolInterruptPending= false;
3030
volatileboolQueryCancelPending= false;
3131
volatileboolProcDiePending= false;
32+
volatileboolClientConnectionLost= false;
3233
volatileboolImmediateInterruptOK= false;
3334
volatileuint32InterruptHoldoffCount=0;
3435
volatileuint32CritSectionCount=0;

‎src/include/miscadmin.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@
5555
* course, only if the interrupt holdoff counter is zero).See the
5656
* related code for details.
5757
*
58+
* A lost connection is handled similarly, although the loss of connection
59+
* does not raise a signal, but is detected when we fail to write to the
60+
* socket. If there was a signal for a broken connection, we could make use of
61+
* it by setting ClientConnectionLost in the signal handler.
62+
*
5863
* A related, but conceptually distinct, mechanism is the "critical section"
5964
* mechanism. A critical section not only holds off cancel/die interrupts,
6065
* but causes any ereport(ERROR) or ereport(FATAL) to become ereport(PANIC)
@@ -70,6 +75,8 @@ extern PGDLLIMPORT volatile bool InterruptPending;
7075
externvolatileboolQueryCancelPending;
7176
externvolatileboolProcDiePending;
7277

78+
externvolatileboolClientConnectionLost;
79+
7380
/* these are marked volatile because they are examined by signal handlers: */
7481
externvolatileboolImmediateInterruptOK;
7582
externPGDLLIMPORTvolatileuint32InterruptHoldoffCount;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp