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

Commitaef3623

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 parent6fcc40b commitaef3623

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
@@ -3120,8 +3120,14 @@ do_connect(enum trivalue reuse_previous_specification,
31203120
pg_log_error("\\connect: %s",PQerrorMessage(n_conn));
31213121
if (o_conn)
31223122
{
3123+
/*
3124+
* Transition to having no connection. Keep this bit in sync
3125+
* with CheckConnection().
3126+
*/
31233127
PQfinish(o_conn);
31243128
pset.db=NULL;
3129+
ResetCancelConn();
3130+
UnsyncVariables();
31253131
}
31263132
}
31273133

@@ -3135,7 +3141,8 @@ do_connect(enum trivalue reuse_previous_specification,
31353141

31363142
/*
31373143
* Replace the old connection with the new one, and update
3138-
* connection-dependent variables.
3144+
* connection-dependent variables. Keep the resynchronization logic in
3145+
* sync with CheckConnection().
31393146
*/
31403147
PQsetNoticeProcessor(n_conn,NoticeProcessor,NULL);
31413148
pset.db=n_conn;
@@ -3226,7 +3233,8 @@ connection_warnings(bool in_startup)
32263233
sverbuf,sizeof(sverbuf)));
32273234

32283235
#ifdefWIN32
3229-
checkWin32Codepage();
3236+
if (in_startup)
3237+
checkWin32Codepage();
32303238
#endif
32313239
printSSLInfo();
32323240
printGSSInfo();

‎src/bin/psql/common.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,13 +402,27 @@ CheckConnection(void)
402402
if (!OK)
403403
{
404404
fprintf(stderr,_("Failed.\n"));
405+
406+
/*
407+
* Transition to having no connection. Keep this bit in sync with
408+
* do_connect().
409+
*/
405410
PQfinish(pset.db);
406411
pset.db=NULL;
407412
ResetCancelConn();
408413
UnsyncVariables();
409414
}
410415
else
416+
{
411417
fprintf(stderr,_("Succeeded.\n"));
418+
419+
/*
420+
* Re-sync, just in case anything changed. Keep this in sync with
421+
* do_connect().
422+
*/
423+
SyncVariables();
424+
connection_warnings(false);/* Must be after SyncVariables */
425+
}
412426
}
413427

414428
returnOK;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp