pg.ddx.io  pgsql-odbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Craig Ringer <craig@2ndquadrant.com>
To: Inoue, Hiroshi <inoue@tpf.co.jp>
Cc: pgsql-odbc@postgresql.org <pgsql-odbc@postgresql.org>
Subject: Re: Protocol de-synchronisation bug, bogus query sent
Date: Thu, 19 Jun 2014 12:56:25 +0800
Message-ID: <53A26D79.1070601@2ndquadrant.com> (raw)
In-Reply-To: <53A26635.4030200@tpf.co.jp>
References: <53A25C95.707@2ndquadrant.com>
	<53A26635.4030200@tpf.co.jp>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-odbc>

On 06/19/2014 12:25 PM, Inoue, Hiroshi wrote:
> 
> 
> The code seems for v0/v1 protocol. Though I don't remember well, the
> dance was probably because v0/v1 didn't have clear sync mechanism.
> I wonder why the code reached there. The flag beforeV2 is broken?

Hm, yes.

beforeV2 seems to be 1, somehow. But only on these "isolated"
connections established via the callstack:


CC_connect(...) with trimmed conninfo

+		dsn	 ""
+		desc	 ""
+		drivername	 "{PostgreSQL ANSI}"
+		server	 "LOCALHOST"
+		database	 "XXXX"
+		username	 "Administrator"
+		protocol	 "7.4"
+		port	 "5432"
+		sslmode	 "disable"
+		conn_settings	{name=0x02e68fb0 "set search_path to
femsconfig_femsmqsv1601" }	pgNAME
		use_server_side_prepare	1 '\x1'	char
		lower_case_identifier	0 '\0'	char
		rollback_on_error	-1 'ΓΏ'	char
		force_abbrev_connstr	0 '\0'	char
		autocommit_public	1 '\x1'	char
		extra_opts	0	unsigned int
		xa_opt	1 '\x1'	char

PgDtc_connect(...)
IAsyncPG::getLockedXAConn()
IAsyncPG::RequestExec(...)  with CommitExec
DtcRequestExec(...)


that hit the problematic code in:

>  	psqlodbc30a.dll!CC_send_query_append(ConnectionClass_ * self, const char * query, QueryInfo_ * qi, unsigned long flag, StatementClass_ * stmt, const char * appendq) Line 3082	C
>  	psqlodbc30a.dll!SC_execute(StatementClass_ * self) Line 2092	C
>  	psqlodbc30a.dll!Exec_with_parameters_resolved(StatementClass_ * stmt, int * exec_end) Line 511	C
>  	psqlodbc30a.dll!PGAPI_Execute(void * hstmt, unsigned short flag) Line 1150	C
>  	psqlodbc30a.dll!PGAPI_ExecDirect(void * hstmt, const unsigned char * szSqlStr, long cbSqlStr, unsigned short flag) Line 195	C
>>	psqlodbc30a.dll!CC_send_settings(ConnectionClass_ * self) Line 3794	C
>  	psqlodbc30a.dll!CC_connect(ConnectionClass_ * self, char password_req, char * salt_para) Line 2187	C
>  	psqlodbc30a.dll!PgDtc_connect(void * self) Line 4471	C
>  	pgenlista.dll!IAsyncPG::getLockedXAConn() Line 597	C++
>  	pgenlista.dll!IAsyncPG::RequestExec(unsigned long type, HRESULT res) Line 657	C++
>  	pgenlista.dll!DtcRequestExec(void * para) Line 996	C++

The conninfo says it clearly _wants_ to use the V3 protocol. Hm. Maybe
the flag is not set up yet because the connection params are still being
sent? Nope, it's set at the top of CC_send_query_append.

However, the version is garbage:

		pg_version	0x02d08830 ""	char[128]
		pg_version_number	0.000000000	float
		pg_version_major	0	short
		pg_version_minor	0	short


Unsurprisingly, version 0 is not >= 7.4 .

So there's at least another bug here causing the version to be zero. It
looks like that's because the connection isn't established yet, per
connection.c:2187:


 /*
  * Since these functions allocate statements, and since the connection
  * is not established yet, it would violate odbc state transition
  * rules.  Therefore, these functions call the corresponding local
  * function instead.
  */
inolog("CC_send_settings\n");
  retsend = CC_send_settings(self);


and we're attempting to use the version obtained from the server before
we have it, instead of the conninfo-specified version to use for
protocol selection purposes.

A debug-mode assertion in the SERVER_VERSION_GT, SERVER_VERSION_GT and
SERVER_VERSION_EQ macros that bailed out if the version was 0 and it's
in the debug configuration would help, I think. Inclined to accept a
patch? If so, how does a newbie Windows programmer like me actually *do*
such an assertion in Windows-y code?



-- 
 Craig Ringer                   http://www.2ndQuadrant.com/
 PostgreSQL Development, 24x7 Support, Training & Services


-- 
Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-odbc



view thread (11+ messages)  latest in thread

Message-ID: <53A26D79.1070601@2ndquadrant.com>
Permalink:  ../53A26D79.1070601@2ndquadrant.com/
Also on:    postgresql.org/message-id/53A26D79.1070601@2ndquadrant.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-odbc@postgresql.org
  Cc: craig@2ndquadrant.com, inoue@tpf.co.jp
  Subject: Re: Protocol de-synchronisation bug, bogus query sent
  In-Reply-To: <53A26D79.1070601@2ndquadrant.com>
  References: <53A25C95.707@2ndquadrant.com> <53A26635.4030200@tpf.co.jp> <53A26D79.1070601@2ndquadrant.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox