public inbox for [email protected]
help / color / mirror / Atom feedBUG: CC_send_query_append incomplete error handling
2+ messages / 2 participants
[nested] [flat]
* BUG: CC_send_query_append incomplete error handling
@ 2021-12-30 13:01 Nicolae Vartolomei <[email protected]>
2022-01-04 04:21 ` Re: BUG: CC_send_query_append incomplete error handling Inoue,Hiroshi <[email protected]>
0 siblings, 1 reply; 2+ messages in thread
From: Nicolae Vartolomei @ 2021-12-30 13:01 UTC (permalink / raw)
To: pgsql-odbc
Hi,
I noticed a bug where psqlodbc doesn't handle an underlying error correctly.
The interaction is roughly as follows:
Initiate a connection, run few queries, run `ss -K dport postgresql` to kill the
psqlodbc connection to postgres, then run another query.
The expected behaviour is for query to fail and to return an error like "08S01".
Instead, the following error is generated:
```
pgapi30.c[PGAPI_GetDiagRec]43: entering type=3 rec=1
environ.c[ER_ReturnError]202: entering status = 1, msg = #no
connection to the server...
environ.c[ER_ReturnError]259: szSqlState = 'HY000',len=58,
szError='no connection to the server
```
This makes it a bit tricky to properly handle the exception on the client.
I'm browsing through this code base for the first time,
and the incomplete error handling seems to be around these lines in connection.c
```
if (!PQsendQuery(self->pqconn, query_buf.data))
{
char *errmsg = PQerrorMessage(self->pqconn);
QLOG(0, "\nCommunication Error: %s\n", SAFE_STR(errmsg));
CC_set_error(self, CONNECTION_COMMUNICATION_ERROR, errmsg, func);
goto cleanup;
}
```
I think this need a call to `CC_on_abort(self, CONN_DEAD);` in order
to clean up the connection so that future calls would get trapped by
`SC_connection_lost_check` call
which also propagates the correct error to `SQLGetDiagRec` with a
statement handle.
Latest tested version is from this package
https://packages.ubuntu.com/focal/odbc-postgresql
Let me know if a test case for reproducing the issue is needed. The
issue affects this code
https://github.com/ClickHouse/ClickHouse/blob/86040a15d80c9371639ee0fac2879da749612a3f/programs/odbc...
(nanodbc->unixODBC->psqlodbc)
---
nvartolomei
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: BUG: CC_send_query_append incomplete error handling
2021-12-30 13:01 BUG: CC_send_query_append incomplete error handling Nicolae Vartolomei <[email protected]>
@ 2022-01-04 04:21 ` Inoue,Hiroshi <[email protected]>
0 siblings, 0 replies; 2+ messages in thread
From: Inoue,Hiroshi @ 2022-01-04 04:21 UTC (permalink / raw)
To: Nicolae Vartolomei <[email protected]>; +Cc: pgsql-odbc
Hi Nicolae,
Sorry for the late reply.
I would take care of this issue.
regards,
Hhiroshi Inoue
2022年1月1日(土) 20:32 Nicolae Vartolomei <[email protected]>:
> Hi,
>
> I noticed a bug where psqlodbc doesn't handle an underlying error
> correctly.
>
> The interaction is roughly as follows:
>
> Initiate a connection, run few queries, run `ss -K dport postgresql` to
> kill the
> psqlodbc connection to postgres, then run another query.
>
> The expected behaviour is for query to fail and to return an error like
> "08S01".
>
> Instead, the following error is generated:
> ```
> pgapi30.c[PGAPI_GetDiagRec]43: entering type=3 rec=1
> environ.c[ER_ReturnError]202: entering status = 1, msg = #no
> connection to the server...
> environ.c[ER_ReturnError]259: szSqlState = 'HY000',len=58,
> szError='no connection to the server
> ```
>
> This makes it a bit tricky to properly handle the exception on the client.
>
> I'm browsing through this code base for the first time,
> and the incomplete error handling seems to be around these lines in
> connection.c
>
> ```
> if (!PQsendQuery(self->pqconn, query_buf.data))
> {
> char *errmsg = PQerrorMessage(self->pqconn);
> QLOG(0, "\nCommunication Error: %s\n", SAFE_STR(errmsg));
> CC_set_error(self, CONNECTION_COMMUNICATION_ERROR, errmsg, func);
> goto cleanup;
> }
> ```
>
> I think this need a call to `CC_on_abort(self, CONN_DEAD);` in order
> to clean up the connection so that future calls would get trapped by
> `SC_connection_lost_check` call
> which also propagates the correct error to `SQLGetDiagRec` with a
> statement handle.
>
> Latest tested version is from this package
> https://packages.ubuntu.com/focal/odbc-postgresql
>
> Let me know if a test case for reproducing the issue is needed. The
> issue affects this code
>
> https://github.com/ClickHouse/ClickHouse/blob/86040a15d80c9371639ee0fac2879da749612a3f/programs/odbc...
> (nanodbc-
> <https://github.com/ClickHouse/ClickHouse/blob/86040a15d80c9371639ee0fac2879da749612a3f/programs/odbc...;
> >unixODBC->psqlodbc)
>
> ---
>
> nvartolomei
>
>
>
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2022-01-04 04:21 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2021-12-30 13:01 BUG: CC_send_query_append incomplete error handling Nicolae Vartolomei <[email protected]>
2022-01-04 04:21 ` Inoue,Hiroshi <[email protected]>
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox