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

Commit22447db

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 parentd1e0f40 commit22447db

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

‎src/backend/tcop/postgres.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4085,12 +4085,12 @@ PostgresSingleUserMain(int argc, char *argv[],
40854085
void
40864086
PostgresMain(constchar*dbname,constchar*username)
40874087
{
4088-
intfirstchar;
4089-
StringInfoDatainput_message;
40904088
sigjmp_buflocal_sigjmp_buf;
4089+
4090+
/* these must be volatile to ensure state is preserved across longjmp: */
40914091
volatileboolsend_ready_for_query= true;
4092-
boolidle_in_transaction_timeout_enabled= false;
4093-
boolidle_session_timeout_enabled= false;
4092+
volatileboolidle_in_transaction_timeout_enabled= false;
4093+
volatileboolidle_session_timeout_enabled= false;
40944094

40954095
AssertArg(dbname!=NULL);
40964096
AssertArg(username!=NULL);
@@ -4296,8 +4296,10 @@ PostgresMain(const char *dbname, const char *username)
42964296
* query cancels from being misreported as timeouts in case we're
42974297
* forgetting a timeout cancel.
42984298
*/
4299-
disable_all_timeouts(false);
4300-
QueryCancelPending= false;/* second to avoid race condition */
4299+
disable_all_timeouts(false);/* do first to avoid race condition */
4300+
QueryCancelPending= false;
4301+
idle_in_transaction_timeout_enabled= false;
4302+
idle_session_timeout_enabled= false;
43014303

43024304
/* Not reading from the client anymore. */
43034305
DoingCommandRead= false;
@@ -4386,6 +4388,9 @@ PostgresMain(const char *dbname, const char *username)
43864388

43874389
for (;;)
43884390
{
4391+
intfirstchar;
4392+
StringInfoDatainput_message;
4393+
43894394
/*
43904395
* At top of loop, reset extended-query-message flag, so that any
43914396
* errors encountered in "idle" state don't provoke skip.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp