Re: FE/BE protocol oddity

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: FE/BE protocol oddity
Дата
Msg-id 5427.994365483@sss.pgh.pa.us
обсуждение исходный текст
Ответ на FE/BE protocol oddity  (Peter Eisentraut <peter_e@gmx.net>)
Ответы Re: FE/BE protocol oddity  (Peter Eisentraut <peter_e@gmx.net>)
Список pgsql-hackers
Peter Eisentraut <peter_e@gmx.net> writes:
> However, libpq doesn't do that.  Instead, it leaves the connection open
> and returns CONNECTION_BAD to the client.  The client would then
> presumably call something like PQfinish(), which sends a Terminate message
> and closes the connection.  This happened to not confuse the <=7.1
> postmasters because they were waiting for 4 bytes and treated the early
> connection close appropriately.

Good point.  Probably, PQfinish should only send the X message if the
connection has gotten past the authentication stage.  A separate but
also useful change would be to do immediate socket close on detecting
auth failure, before returning to the client application.

> On this occasion let me also point out that

>     pqPuts("X", conn);

> is not the way to send a single byte 'X' to the server.

Huh?  Oh, the trailing null byte.  You're right, it should bepqPutnchar("X", 1, conn);

> So I figured I would sneak in a check for connection close before reading
> the authentication response in the server, but since the frontends seems
> to be doing what they want I don't really know what to check for.

Seems reasonable, with the understanding that we'll still generate the
silly log messages when talking to an old client.  However...

> Btw., is recv(sock, x, 1, MSG_PEEK) == 0 an appropriate way to check for a
> closed connection without reading anything?

Seems a little risky as far as portability goes; is MSG_PEEK supported
on BeOS, Darwin, Cygwin, etc?  Might be better to fix the backend libpq
routines to understand whether a connection-close event is expected or
not, and only emit a complaint to the log when it's not.  Not sure how
far such a change would need to propagate though...
        regards, tom lane


В списке pgsql-hackers по дате отправления:

Предыдущее
От: Bruce Momjian
Дата:
Сообщение: Solaris source code
Следующее
От: Naomi Walker
Дата:
Сообщение: Re: Solaris source code