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

Commit0c32818

Browse files
committed
Be more rigorous about local variables in PostgresMain().
Since PostgresMain calls sigsetjmp, any local variables that are notmarked "volatile" have a risk of unspecified behavior. In practicethis means that when control returns via longjmp, such variables mightget reset to their values as of the time of sigsetjmp, depending onwhether the compiler chose to put them in registers or on the stack.We were careful about this for "send_ready_for_query", but not theother local variables.In the case of the timeout_enabled flags, resetting them totheir initial "false" states is actually good, since we do"disable_all_timeouts()" in the longjmp cleanup code path. If thatdoes not happen, we risk uselessly calling "disable_timeout()" later,which is harmless but a little bit expensive. Let's explicitly resetthese flags so that the behavior is correct and platform-independent.(This change means that we really don't need the new "volatile"markings after all, but let's install them anyway since any changein this logic could re-introduce a problem.)There is no issue for "firstchar" and "input_message" because thoseare explicitly reinitialized each time through the query processingloop. To make that clearer, move them to be declared inside the loop.That leaves us with all the function-lifespan locals except thesigjmp_buf itself marked as volatile, which seems like a good policyto have going forward.Because of the possibility of extra disable_timeout() calls, thisseems worth back-patching.Sergey Shinderuk and Tom LaneDiscussion:https://postgr.es/m/2eda015b-7dff-47fd-d5e2-f1a9899b90a6@postgrespro.ru
1 parent02021f1 commit0c32818

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

‎src/backend/tcop/postgres.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3753,11 +3753,11 @@ PostgresMain(int argc, char *argv[],
37533753
constchar*dbname,
37543754
constchar*username)
37553755
{
3756-
intfirstchar;
3757-
StringInfoDatainput_message;
37583756
sigjmp_buflocal_sigjmp_buf;
3757+
3758+
/* these must be volatile to ensure state is preserved across longjmp: */
37593759
volatileboolsend_ready_for_query= true;
3760-
booldisable_idle_in_transaction_timeout= false;
3760+
volatilebooldisable_idle_in_transaction_timeout= false;
37613761

37623762
/* Initialize startup process environment if necessary. */
37633763
if (!IsUnderPostmaster)
@@ -4042,9 +4042,10 @@ PostgresMain(int argc, char *argv[],
40424042
* query cancels from being misreported as timeouts in case we're
40434043
* forgetting a timeout cancel.
40444044
*/
4045-
disable_all_timeouts(false);
4046-
QueryCancelPending= false;/* second to avoid race condition */
4045+
disable_all_timeouts(false);/* do first to avoid race condition */
4046+
QueryCancelPending= false;
40474047
stmt_timeout_active= false;
4048+
disable_idle_in_transaction_timeout= false;
40484049

40494050
/* Not reading from the client anymore. */
40504051
DoingCommandRead= false;
@@ -4133,6 +4134,9 @@ PostgresMain(int argc, char *argv[],
41334134

41344135
for (;;)
41354136
{
4137+
intfirstchar;
4138+
StringInfoDatainput_message;
4139+
41364140
/*
41374141
* At top of loop, reset extended-query-message flag, so that any
41384142
* errors encountered in "idle" state don't provoke skip.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp