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

Commit5524ef5

Browse files
committed
Handle corner cases correctly in psql's reconnection logic.
After an unexpected connection loss and successful reconnection,psql neglected to resynchronize its internal state about the server,such as server version. Ordinarily we'd be reconnecting to the sameserver and so this isn't really necessary, but there are scenarioswhere we do need to update --- one example is where we have a listof possible connection targets and they're not all alike.Define "resynchronize" as including connection_warnings(), so thatthis case acts the same as \connect. This seems useful; for example,if the server version did change, the user might wish to know that.An attuned user might also notice that the new connection isn'tSSL-encrypted, for example, though this approach isn't especiallyin-your-face about such changes. Although this part is a behavioralchange, it only affects interactive sessions, so it should not breakany applications.Also, in do_connect, make sure that we desynchronize correctly whenabandoning an old connection in non-interactive mode.These problems evidently are the result of people patching only oneof the two places where psql deals with connection changes, so insertsome cross-referencing comments in hopes of forestalling future bugsof the same ilk.Lastly, in Windows builds, issue codepage mismatch warnings only atstartup, not during reconnections. psql's codepage can't changeduring a reconnect, so complaining about it again seems like uselessnoise.Peter Billen and Tom Lane. Back-patch to all supported branches.Discussion:https://postgr.es/m/CAMTXbE8e6U=EBQfNSe01Ej17CBStGiudMAGSOPaw-ALxM-5jXg@mail.gmail.com
1 parent232f645 commit5524ef5

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

‎src/bin/psql/command.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3041,8 +3041,14 @@ do_connect(enum trivalue reuse_previous_specification,
30413041
psql_error("\\connect: %s",PQerrorMessage(n_conn));
30423042
if (o_conn)
30433043
{
3044+
/*
3045+
* Transition to having no connection. Keep this bit in sync
3046+
* with CheckConnection().
3047+
*/
30443048
PQfinish(o_conn);
30453049
pset.db=NULL;
3050+
ResetCancelConn();
3051+
UnsyncVariables();
30463052
}
30473053
}
30483054

@@ -3056,7 +3062,8 @@ do_connect(enum trivalue reuse_previous_specification,
30563062

30573063
/*
30583064
* Replace the old connection with the new one, and update
3059-
* connection-dependent variables.
3065+
* connection-dependent variables. Keep the resynchronization logic in
3066+
* sync with CheckConnection().
30603067
*/
30613068
PQsetNoticeProcessor(n_conn,NoticeProcessor,NULL);
30623069
pset.db=n_conn;
@@ -3131,7 +3138,8 @@ connection_warnings(bool in_startup)
31313138
sverbuf,sizeof(sverbuf)));
31323139

31333140
#ifdefWIN32
3134-
checkWin32Codepage();
3141+
if (in_startup)
3142+
checkWin32Codepage();
31353143
#endif
31363144
printSSLInfo();
31373145
}

‎src/bin/psql/common.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,13 +423,27 @@ CheckConnection(void)
423423
if (!OK)
424424
{
425425
psql_error("Failed.\n");
426+
427+
/*
428+
* Transition to having no connection. Keep this bit in sync with
429+
* do_connect().
430+
*/
426431
PQfinish(pset.db);
427432
pset.db=NULL;
428433
ResetCancelConn();
429434
UnsyncVariables();
430435
}
431436
else
437+
{
432438
psql_error("Succeeded.\n");
439+
440+
/*
441+
* Re-sync, just in case anything changed. Keep this in sync with
442+
* do_connect().
443+
*/
444+
SyncVariables();
445+
connection_warnings(false);/* Must be after SyncVariables */
446+
}
433447
}
434448

435449
returnOK;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp