pg.ddx.io pgsql-odbc@postgresql.org mailing list archive
help / color / mirror / Atom feedmsdtc with 32-bit app fails to resolve in-doubt or not-notifed transactions
11+ messages / 2 participants
[nested] [flat]
Commits from this thread:
2014-06-27 e3f180ac63 Fix driver name mismatch between 32-bit ODBC app and 64-bit MSDTC host
* msdtc with 32-bit app fails to resolve in-doubt or not-notifed transactions
@ 2014-06-20 16:03 Craig Ringer <craig@2ndquadrant.com>
0 siblings, 1 reply; 11+ messages in thread
From: Craig Ringer @ 2014-06-20 16:03 UTC (permalink / raw)
To: pgsql-odbc
Hi folks
I've found an issue with psqlODBC's MSDTC support and pgxalib.dll, where
a 32-bit application on a 64-bit server will intermittently leave
transactions in the "only failed to notify" state in MSDTC.
This occurs when:
- The application exits normally after its final ITransaction::Commit
call returns but before MSDTC has invoked
ITransactionResourceAsync::CommitRequest on the psqlODBC-provided
IAsyncPG object; or
- When the application or server crash after MSDTC Phase I but before
Phase II.
In both these cases the resource manager is supposed to handle
transaction resolution. It uses pgxalib.dll for this as that's the
registered XA co-ordinator for the resource type.
I've been able to trace pgxalib.dll (which, btw, was painful, will
follow up on that) and found that XAConnection::xa_recover() is being
called on the transaction, as expected. It's calling into
XAConnection::ActivateConnection, where it fails to establish an ODBC
connection and bails out at the test at 142 after getting return code -1
from SQLDriverConnect(...).
http://msdn.microsoft.com/en-us/library/ms716219(v=vs.85).aspx
suggests that this is SQL_ERROR. pgxalib.dll doesn't call SQLGetDiagRec
or SQLGetDiagField to get any details and log them; I'll submit a
separate patch for that.
It took me a while to figure it out, but SQLDriverConnect is failing
because it's using the name of the 32-bit driver, since it got the DSN
from a 32-bit application. So there's no such driver as far as the
64-bit application is concerned.
(It didn't help that I couldn't enable system-wide ODBC tracing on the
system for unrelated and annoying as-yet-unresolved reasons with the
ODBC driver manager).
Anyway - it looks like it'll be necessary to figure out in pgxalib.dll
when this is happening and remap the driver name. That seems pretty
crude, though, so I'm looking for better ideas.
I'll follow up when it's not midnight with:
- a patch to add proper error diagnostics in pgxalib.dll on connection
failure;
- results of testing a hack that just mangles the dsn connection string
manually, as a proof of concept to show that this is really the issue; and
- If I can figure out how to do it the right way (as opposed to just
abusing a breakpoint to set the lvalue on return like I ended up doing),
some documentation on how to turn pgxalib tracing on.
As part of this I've been wondering whether it's possible to deal with
that exit race condition. I'm not sure how to tackle that - I don't
speak fluent COM or OLE. Do you think it'd be legal to delay in the
IAsyncPG dtor until either we confirm commit of an a tx we know is in
flight or we hit a (short) timeout?
--
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
^ permalink raw reply [nested|flat] 11+ messages in thread
* Re: msdtc with 32-bit app fails to resolve in-doubt or not-notifed transactions
@ 2014-06-20 21:34 Inoue, Hiroshi <inoue@tpf.co.jp>
parent: Craig Ringer <craig@2ndquadrant.com>
0 siblings, 1 reply; 11+ messages in thread
From: Inoue, Hiroshi @ 2014-06-20 21:34 UTC (permalink / raw)
To: Craig Ringer <craig@2ndquadrant.com>; +Cc: pgsql-odbc
(2014/06/21 1:03), Craig Ringer wrote:
> Hi folks
>
> I've found an issue with psqlODBC's MSDTC support and pgxalib.dll, where
> a 32-bit application on a 64-bit server will intermittently leave
> transactions in the "only failed to notify" state in MSDTC.
>
> This occurs when:
>
> - The application exits normally after its final ITransaction::Commit
> call returns but before MSDTC has invoked
> ITransactionResourceAsync::CommitRequest on the psqlODBC-provided
> IAsyncPG object; or
>
> - When the application or server crash after MSDTC Phase I but before
> Phase II.
>
> In both these cases the resource manager is supposed to handle
> transaction resolution. It uses pgxalib.dll for this as that's the
> registered XA co-ordinator for the resource type.
>
> I've been able to trace pgxalib.dll (which, btw, was painful, will
> follow up on that) and found that XAConnection::xa_recover() is being
> called on the transaction, as expected. It's calling into
> XAConnection::ActivateConnection, where it fails to establish an ODBC
> connection and bails out at the test at 142 after getting return code -1
> from SQLDriverConnect(...).
>
> http://msdn.microsoft.com/en-us/library/ms716219(v=vs.85).aspx
>
> suggests that this is SQL_ERROR. pgxalib.dll doesn't call SQLGetDiagRec
> or SQLGetDiagField to get any details and log them; I'll submit a
> separate patch for that.
>
> It took me a while to figure it out, but SQLDriverConnect is failing
> because it's using the name of the 32-bit driver,
Oops, it's my mistake. It may be better to rewrite the code completely
using libpq APIs instead of ODBC APIs.
> since it got the DSN
> from a 32-bit application. So there's no such driver as far as the
> 64-bit application is concerned.
>
> (It didn't help that I couldn't enable system-wide ODBC tracing on the
> system for unrelated and annoying as-yet-unresolved reasons with the
> ODBC driver manager).
>
> Anyway - it looks like it'll be necessary to figure out in pgxalib.dll
> when this is happening and remap the driver name. That seems pretty
> crude, though, so I'm looking for better ideas.
>
> I'll follow up when it's not midnight with:
>
> - a patch to add proper error diagnostics in pgxalib.dll on connection
> failure;
>
> - results of testing a hack that just mangles the dsn connection string
> manually, as a proof of concept to show that this is really the issue; and
>
> - If I can figure out how to do it the right way (as opposed to just
> abusing a breakpoint to set the lvalue on return like I ended up doing),
> some documentation on how to turn pgxalib tracing on.
>
>
> As part of this I've been wondering whether it's possible to deal with
> that exit race condition. I'm not sure how to tackle that - I don't
> speak fluent COM or OLE. Do you think it'd be legal to delay in the
> IAsyncPG dtor until either we confirm commit of an a tx we know is in
> flight or we hit a (short) timeout?
>
--
Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-odbc
^ permalink raw reply [nested|flat] 11+ messages in thread
* Re: msdtc with 32-bit app fails to resolve in-doubt or not-notifed transactions
@ 2014-06-21 04:52 Craig Ringer <craig@2ndquadrant.com>
parent: Inoue, Hiroshi <inoue@tpf.co.jp>
0 siblings, 1 reply; 11+ messages in thread
From: Craig Ringer @ 2014-06-21 04:52 UTC (permalink / raw)
To: Inoue, Hiroshi <inoue@tpf.co.jp>; +Cc: pgsql-odbc
> Oops, it's my mistake. It may be better to rewrite the code completely
> using libpq APIs instead of ODBC APIs.
I don't know if that'll work.
Nothing requires the transaction co-ordinator to be local to the
database. The ODBC app using the local MSDTC might be talking to an
Amazon RDS instance for all we know or care. All the local transaction
co-ordinator needs is to be able to talk to the database.
That becomes a problem if the user is using a pre-defined System DSN,
User DSN or File DSN rather than a string DSN like in the test case I've
been working with. At least with a string DSN we can parse out the
relevant details and make a libpq connection. With indirect DSNs we
can't do that (AFAIK), we'd need a way to ask ODBC / psqlODBC what the
connection parameters were in a way we could pass to libpq.
OTOH, the same issue seems to rule out just rewriting the driver name in
the connection string. We can't do that if it's indirect via a file,
user or system DSN, AFAIK.
I'll need to read a bunch of documentation and do some more testing
before I'm confident of any of that, though.
--
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
^ permalink raw reply [nested|flat] 11+ messages in thread
* Re: msdtc with 32-bit app fails to resolve in-doubt or not-notifed transactions
@ 2014-06-21 08:02 Craig Ringer <craig@2ndquadrant.com>
parent: Craig Ringer <craig@2ndquadrant.com>
0 siblings, 1 reply; 11+ messages in thread
From: Craig Ringer @ 2014-06-21 08:02 UTC (permalink / raw)
To: Inoue, Hiroshi <inoue@tpf.co.jp>; +Cc: pgsql-odbc
On 06/21/2014 12:52 PM, Craig Ringer wrote:
>
>> Oops, it's my mistake. It may be better to rewrite the code completely
>> using libpq APIs instead of ODBC APIs.
>
> I don't know if that'll work.
... and in fact there are more issues, too.
If the DSN is using SSPI, MSDTC.exe probably won't be able to
authenticate to the DB as them. Same with any other kind of connection
that depends on the properties of the current user account.
Meh.
Given the low uptake of MSDTC and XA with Pg I think a lot of this can
just be documented away - "don't do that". So I'm not going to go
charging around trying to find 100% perfect solutions at the expense of
"good enough for the real world".
Where possible I'd like to find ways to produce useful errors though,
preferably at transaction enlistment time rather than commit phase II.
Suggestions would be valued.
--
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
^ permalink raw reply [nested|flat] 11+ messages in thread
* Re: msdtc with 32-bit app fails to resolve in-doubt or not-notifed transactions
@ 2014-06-23 00:34 Inoue, Hiroshi <inoue@tpf.co.jp>
parent: Craig Ringer <craig@2ndquadrant.com>
0 siblings, 1 reply; 11+ messages in thread
From: Inoue, Hiroshi @ 2014-06-23 00:34 UTC (permalink / raw)
To: Craig Ringer <craig@2ndquadrant.com>; +Cc: pgsql-odbc
(2014/06/21 17:02), Craig Ringer wrote:
> On 06/21/2014 12:52 PM, Craig Ringer wrote:
>>
>>> Oops, it's my mistake. It may be better to rewrite the code completely
>>> using libpq APIs instead of ODBC APIs.
>>
>> I don't know if that'll work.
The driver doesn't pass original connection strings to XARMCreate().
It seems possible to pass LIBPQ connection strings.
>
> ... and in fact there are more issues, too.
>
> If the DSN is using SSPI, MSDTC.exe probably won't be able to
> authenticate to the DB as them. Same with any other kind of connection
> that depends on the properties of the current user account.
>
> Meh.
Yes it's a severe problem.
I'll try to check the good way to do it.
> Given the low uptake of MSDTC and XA with Pg I think a lot of this can
> just be documented away - "don't do that". So I'm not going to go
> charging around trying to find 100% perfect solutions at the expense of
> "good enough for the real world".
>
> Where possible I'd like to find ways to produce useful errors though,
> preferably at transaction enlistment time rather than commit phase II.
> Suggestions would be valued.
It's possible to reject transaction enlistments at XARMCreate() though
I'm not sure if it's possible to tell the cause clearly to users.
regards,
Hiroshi Inoue
--
I am using the free version of SPAMfighter.
SPAMfighter has removed 11041 of my spam emails to date.
Get the free SPAMfighter here: http://www.spamfighter.com/len
Do you have a slow PC? Try a Free scan
http://www.spamfighter.com/SLOW-PCfighter?cid=sigen
--
Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-odbc
^ permalink raw reply [nested|flat] 11+ messages in thread
* Re: msdtc with 32-bit app fails to resolve in-doubt or not-notifed transactions
@ 2014-06-23 01:23 Craig Ringer <craig@2ndquadrant.com>
parent: Inoue, Hiroshi <inoue@tpf.co.jp>
0 siblings, 1 reply; 11+ messages in thread
From: Craig Ringer @ 2014-06-23 01:23 UTC (permalink / raw)
To: Inoue, Hiroshi <inoue@tpf.co.jp>; +Cc: pgsql-odbc
On 06/23/2014 08:34 AM, Inoue, Hiroshi wrote:
> (2014/06/21 17:02), Craig Ringer wrote:
>> On 06/21/2014 12:52 PM, Craig Ringer wrote:
>>>
>>>> Oops, it's my mistake. It may be better to rewrite the code completely
>>>> using libpq APIs instead of ODBC APIs.
>>>
>>> I don't know if that'll work.
>
> The driver doesn't pass original connection strings to XARMCreate().
> It seems possible to pass LIBPQ connection strings.
Ah, I misunderstood that then.
Great, that makes life easier.
>> If the DSN is using SSPI, MSDTC.exe probably won't be able to
>> authenticate to the DB as them. Same with any other kind of connection
>> that depends on the properties of the current user account.
>
> Yes it's a severe problem.
> I'll try to check the good way to do it.
Thanks for thinking about it.
>> Where possible I'd like to find ways to produce useful errors though,
>> preferably at transaction enlistment time rather than commit phase II.
>> Suggestions would be valued.
>
> It's possible to reject transaction enlistments at XARMCreate() though
> I'm not sure if it's possible to tell the cause clearly to users.
That'll be handy. As for telling users, we can always emit a message to
the Windows Event Log. Competent admins should be looking there anyway.
However, AFAIK we have no way to find out in advance if a connstring or
DSN passed by the driver to msdtc for use in pgxalib will actually be
usable - in particular we have no way to query `pg_hba.conf` to see (a)
how our current connection was authenticated and (b) whether the same
connection settings would apply for the pgxalib connection. For example,
I don't think there's any way to tell if our current user/host/db combo
has a special cased 'trust' entry in pg_hba.conf that means other combos
will require a password.
So I don't think there'll be any robust solution to this that doesn't
involve just documenting it away to some degree.
I suspect we'll land up wanting a multi-part solution:
- Use libpq in pgxalib and pass libpq connstrings generated from the dsn
by the odbc driver during tx enlistment to bypass the driver name issue;
- Provide a configuration option (an odbcinst.ini registry key?) to
allow the operator to override the driver-generated dsn/connstr used by
pgxalib with one the user knows will allow superuser connections to the
DB. If it exists this is used instead of any driver-generated connstring
for 2PC.
- Provide an ODBC parameter to set an escaped connection string for use
in XA management (?). Alternative to / override for the above registry
setting. This probably isn't necessary, as apps already have to set a
few registry keys to make XA work with MSDTC at all.
- Document XA configuration, noting that if SSPI is in use a connstring
*must* be configured. A user should be created for the purpose of XA 2PC
management and given precedence above SSPI connections in pg_hba.conf;
otherwise if SSPI works at all for NETWORKSERVICE you'd be giving every
NETWORKSERVICE app potential access to the db(s), which would be
undesirable.
I'm happy to write the required documentation, not least because I need
to document how to configure pgxalib with msdtc anyway - adding the
missing registry key for older versions, enabling XA support in msdtc in
component services, where to find the logs, how to enable msdtc's
tracing, how to enable pgxalib's tracing (if I can figure that out), how
to monitor for incomplete 2PC transactions, etc.
How *does* one correctly enable pgxalib tracing? I tried creating a
registry key "PostgreSQL" under "odbcinst.ini" in
HKLM\SOFTWARE\ODBC\ODBCINST.INI and adding a String value "Msdtclog"
with content '1' (no quotes). The key didn't seem to get found by
SQLGetPrivateProfileString though. So I'm not sure what the right way to
turn it on is.
--
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
^ permalink raw reply [nested|flat] 11+ messages in thread
* Re: msdtc with 32-bit app fails to resolve in-doubt or not-notifed transactions
@ 2014-06-23 21:23 Inoue, Hiroshi <inoue@tpf.co.jp>
parent: Craig Ringer <craig@2ndquadrant.com>
0 siblings, 1 reply; 11+ messages in thread
From: Inoue, Hiroshi @ 2014-06-23 21:23 UTC (permalink / raw)
To: Craig Ringer <craig@2ndquadrant.com>; +Cc: pgsql-odbc
(2014/06/23 10:23), Craig Ringer wrote:
> On 06/23/2014 08:34 AM, Inoue, Hiroshi wrote:
>> (2014/06/21 17:02), Craig Ringer wrote:
>>> On 06/21/2014 12:52 PM, Craig Ringer wrote:
>>>>
>>>>> Oops, it's my mistake. It may be better to rewrite the code completely
>>>>> using libpq APIs instead of ODBC APIs.
>>>>
>>>> I don't know if that'll work.
>>
>> The driver doesn't pass original connection strings to XARMCreate().
>> It seems possible to pass LIBPQ connection strings.
>
> Ah, I misunderstood that then.
>
> Great, that makes life easier.
>
>>> If the DSN is using SSPI, MSDTC.exe probably won't be able to
>>> authenticate to the DB as them. Same with any other kind of connection
>>> that depends on the properties of the current user account.
>>
>> Yes it's a severe problem.
>> I'll try to check the good way to do it.
>
> Thanks for thinking about it.
>
>>> Where possible I'd like to find ways to produce useful errors though,
>>> preferably at transaction enlistment time rather than commit phase II.
>>> Suggestions would be valued.
>>
>> It's possible to reject transaction enlistments at XARMCreate() though
>> I'm not sure if it's possible to tell the cause clearly to users.
>
> That'll be handy. As for telling users, we can always emit a message to
> the Windows Event Log. Competent admins should be looking there anyway.
>
> However, AFAIK we have no way to find out in advance if a connstring or
> DSN passed by the driver to msdtc for use in pgxalib will actually be
> usable
XARMCreate() triggers xa_open() ( and xa_close()) probably so as to
check that the XADLL works. Currently xa_open() doesn't connect to
the database and simply saves the connection information for subsequent
xa_commit(), xa_rollback() or xa_recover() call. When original process
finished COMMIT/ROLLBACK PREPARED properly, No database access occurs
in msdtc process. We can change xa_open() so that it connects to the
database immediately and causes an error to XARMCreate() when the
connection fails.
regards,
Hiroshi Inoue
> - in particular we have no way to query `pg_hba.conf` to see (a)
> how our current connection was authenticated and (b) whether the same
> connection settings would apply for the pgxalib connection. For example,
> I don't think there's any way to tell if our current user/host/db combo
> has a special cased 'trust' entry in pg_hba.conf that means other combos
> will require a password.
--
Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-odbc
^ permalink raw reply [nested|flat] 11+ messages in thread
* Re: msdtc with 32-bit app fails to resolve in-doubt or not-notifed transactions
@ 2014-06-24 03:07 Craig Ringer <craig@2ndquadrant.com>
parent: Inoue, Hiroshi <inoue@tpf.co.jp>
0 siblings, 1 reply; 11+ messages in thread
From: Craig Ringer @ 2014-06-24 03:07 UTC (permalink / raw)
To: Inoue, Hiroshi <inoue@tpf.co.jp>; +Cc: pgsql-odbc
On 06/24/2014 05:23 AM, Inoue, Hiroshi wrote:
>
> XARMCreate() triggers xa_open() ( and xa_close()) probably so as to
> check that the XADLL works. Currently xa_open() doesn't connect to
> the database and simply saves the connection information for subsequent
> xa_commit(), xa_rollback() or xa_recover() call. When original process
> finished COMMIT/ROLLBACK PREPARED properly, No database access occurs
> in msdtc process. We can change xa_open() so that it connects to the
> database immediately and causes an error to XARMCreate() when the
> connection fails.
That's enlightening. Thankyou very much.
I'll happily implement that and send in a patch. It may take a week or
two as I have some other projects on the boil, but hopefully it won't
take super long.
--
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
^ permalink raw reply [nested|flat] 11+ messages in thread
* Re: msdtc with 32-bit app fails to resolve in-doubt or not-notifed transactions
@ 2014-06-25 14:26 Craig Ringer <craig@2ndquadrant.com>
parent: Craig Ringer <craig@2ndquadrant.com>
0 siblings, 1 reply; 11+ messages in thread
From: Craig Ringer @ 2014-06-25 14:26 UTC (permalink / raw)
To: Inoue, Hiroshi <inoue@tpf.co.jp>; +Cc: pgsql-odbc
On 06/24/2014 11:07 AM, Craig Ringer wrote:
> On 06/24/2014 05:23 AM, Inoue, Hiroshi wrote:
>>
>> XARMCreate() triggers xa_open() ( and xa_close()) probably so as to
>> check that the XADLL works. Currently xa_open() doesn't connect to
>> the database and simply saves the connection information for subsequent
>> xa_commit(), xa_rollback() or xa_recover() call. When original process
>> finished COMMIT/ROLLBACK PREPARED properly, No database access occurs
>> in msdtc process. We can change xa_open() so that it connects to the
>> database immediately and causes an error to XARMCreate() when the
>> connection fails.
>
> That's enlightening. Thankyou very much.
>
> I'll happily implement that and send in a patch. It may take a week or
> two as I have some other projects on the boil, but hopefully it won't
> take super long.
... and done.
Please merge branch fix-syswow64-msdtc from my repo at
https://github.com/ringerc/psqlODBC.git .
see: https://github.com/ringerc/psqlODBC/pull/2
Patch attached if you prefer that. See patch header and in-code comments
for details.
It may well be better to just rewrite pgxalib.dll to use libpq, but I
wanted to stay non-intrusive and simple if possible. For now at least.
I'm not sure the unicode vs ansi dance is necessary in the patch is
necessary - it's probably ok to just always use the unicode driver.
Again, though, deviating from what the driver already does as little as
possible seemed reasonable.
--
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
Attachments:
0001-Fix-driver-name-mismatch-between-32-bit-ODBC-app-and.patch (text/x-patch, 4.2K) download
From efd31cc9788710c03d73bda4fcb3992145ccc7e8 Mon Sep 17 00:00:00 2001
From: Craig Ringer <craig@2ndquadrant.com>
Date: Wed, 25 Jun 2014 15:17:00 +0800
Subject: [PATCH] Fix driver name mismatch between 32-bit ODBC app and 64-bit
MSDTC host
If the 32-bit driver runs on a 64-bit host within a 32-bit app
running under SysWow64 then XA transactions will fail to recover.
That's because recovery is done by pgxalib.dll which runs within
MSDTC.exe - a 64-bit application. It connects to a DSN supplied
by psqlODBC in EnlistInDtc_1pipe during DTC enlistment by the
XA resource manager. This DSN uses the driver name of the client's
ODBC driver - which is fine so long as the client and MSDTC
architectures match. If they don't then MSDTC will fail to connect
to Pg, so it'll never resolve transactions.
Traces of MSDTC will show RM_COMMIT_DELIVERY_FAILED_DUE_TO_CONNECTION_DOWN
events.
Traces of pgxalib.dll will show xa_recover(..) being entered, followed by
"SQLDriverConnect return=-1".
To fix this, we detect if we're running under SysWow64 by examining the
PROCESSOR_ARCHITEW6432 environment variable and supply the 64-bit driver name
if so.
See mailing list thread:
http://www.postgresql.org/message-id/53A45B59.70303@2ndquadrant.com
for details.
---
connection.c | 42 ++++++++++++++++++++++++++++++++++++++++--
psqlodbc.h | 8 ++++++--
2 files changed, 46 insertions(+), 4 deletions(-)
diff --git a/connection.c b/connection.c
index 794ddde..512482c 100644
--- a/connection.c
+++ b/connection.c
@@ -4362,10 +4362,48 @@ const char *CurrCatString(const ConnectionClass *conn)
DLL_DECLARE void PgDtc_create_connect_string(void *self, char *connstr, int strsize)
{
ConnectionClass *conn = (ConnectionClass *) self;
-
+ SYSTEM_INFO si;
ConnInfo *ci = &(conn->connInfo);
+ const char *drivername = ci->drivername;
+
+#if defined(_WIN32) && !defined(_WIN64)
+ /*
+ * If this is an x86 driver running on an x64 host then the driver name
+ * passed to MSDTC must be the (x64) driver but the client app will be
+ * using the 32-bit driver name. So MSDTC.exe will fail to find the driver
+ * and we'll fail to recover XA transactions.
+ *
+ * IsWow64Process(...) would be the ideal function for this, but is only
+ * available on Windows 6+ (Vista/2k8). We'd use GetNativeSystemInfo, which
+ * is supported on XP and 2k3, instead, but that won't link with older
+ * SDKs.
+ *
+ * It's impler to just test the PROCESSOR_ARCHITEW6432 environment
+ * variable.
+ *
+ * See http://www.postgresql.org/message-id/53A45B59.70303@2ndquadrant.com
+ * for details on this issue.
+ */
+ const char * const procenv = getenv("PROCESSOR_ARCHITEW6432");
+ if (procenv != NULL && strcmp(procenv, "AMD64") == 0)
+ {
+ /*
+ * We're a 32-bit binary running under SysWow64 on a 64-bit host and need
+ * to pass a different driver name.
+ *
+ * To avoid playing memory management games, just return a different
+ * string constant depending on the unicode-ness of the driver.
+ */
+#ifdef UNICODE_SUPPORT
+ drivername = DBMS_NAME_UNICODE;
+#else
+ drivername = DBMS_NAME_ANSI;
+#endif
+ }
+#endif // _WIN32 && !_WIN64
+
snprintf(connstr, strsize, "DRIVER={%s};SERVER=%s;PORT=%s;DATABASE=%s;UID=%s;PWD=%s;" ABBR_SSLMODE "=%s",
- ci->drivername, ci->server, ci->port, ci->database, ci->username, SAFE_NAME(ci->password), ci->sslmode);
+ drivername, ci->server, ci->port, ci->database, ci->username, SAFE_NAME(ci->password), ci->sslmode);
}
DLL_DECLARE void PgDtc_set_async(void *self, void *async)
diff --git a/psqlodbc.h b/psqlodbc.h
index c0c895f..05dcc9e 100644
--- a/psqlodbc.h
+++ b/psqlodbc.h
@@ -249,6 +249,10 @@ typedef double SDOUBLE;
/* Driver stuff */
#define DRIVERNAME "PostgreSQL ODBC"
+
+#define DBMS_NAME_UNICODE "PostgreSQL Unicode"
+#define DBMS_NAME_ANSI "PostgreSQL ANSI"
+
#if (ODBCVER >= 0x0300)
#if (ODBCVER >= 0x0351)
#define DRIVER_ODBC_VER "03.51"
@@ -257,9 +261,9 @@ typedef double SDOUBLE;
#endif /* ODBCVER 0x0351 */
#ifndef DBMS_NAME
#ifdef UNICODE_SUPPORT
-#define DBMS_NAME "PostgreSQL Unicode"
+#define DBMS_NAME DBMS_NAME_UNICODE
#else
-#define DBMS_NAME "PostgreSQL ANSI"
+#define DBMS_NAME DBMS_NAME_ANSI
#endif /* UNICODE_SUPPORT */
#endif /* DBMS_NAME */
#else
--
1.9.0
^ permalink raw reply [nested|flat] 11+ messages in thread
* Re: msdtc with 32-bit app fails to resolve in-doubt or not-notifed transactions
@ 2014-06-25 16:13 Craig Ringer <craig@2ndquadrant.com>
0 siblings, 0 replies; 11+ messages in thread
From: Craig Ringer @ 2014-06-25 16:13 UTC (permalink / raw)
To: Inoue, Hiroshi <inoue@tpf.co.jp>; +Cc: pgsql-odbc
Hi all
I just realised there is an oversight in the patch.
I'll submit an updated one tomorrow.
--
Craig
--
Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-odbc
^ permalink raw reply [nested|flat] 11+ messages in thread
* Re: msdtc with 32-bit app fails to resolve in-doubt or not-notifed transactions
@ 2014-06-26 08:23 Craig Ringer <craig@2ndquadrant.com>
parent: Craig Ringer <craig@2ndquadrant.com>
0 siblings, 0 replies; 11+ messages in thread
From: Craig Ringer @ 2014-06-26 08:23 UTC (permalink / raw)
To: Inoue, Hiroshi <inoue@tpf.co.jp>; +Cc: pgsql-odbc
On 06/25/2014 10:26 PM, Craig Ringer wrote:
> On 06/24/2014 11:07 AM, Craig Ringer wrote:
>> On 06/24/2014 05:23 AM, Inoue, Hiroshi wrote:
>>>
>>> XARMCreate() triggers xa_open() ( and xa_close()) probably so as to
>>> check that the XADLL works. Currently xa_open() doesn't connect to
>>> the database and simply saves the connection information for subsequent
>>> xa_commit(), xa_rollback() or xa_recover() call. When original process
>>> finished COMMIT/ROLLBACK PREPARED properly, No database access occurs
>>> in msdtc process. We can change xa_open() so that it connects to the
>>> database immediately and causes an error to XARMCreate() when the
>>> connection fails.
>>
>> That's enlightening. Thankyou very much.
>>
>> I'll happily implement that and send in a patch. It may take a week or
>> two as I have some other projects on the boil, but hopefully it won't
>> take super long.
>
> ... and done.
>
> Please merge branch fix-syswow64-msdtc from my repo at
> https://github.com/ringerc/psqlODBC.git .
>
> see: https://github.com/ringerc/psqlODBC/pull/2
>
> Patch attached if you prefer that. See patch header and in-code comments
> for details.
Here's the revised patch. I've tested this against the customer's
original test case and it now runs properly. MSDTC correctly recovers
abandoned tx's in which Phase I commit succeeded then the app exited /
crashed before Phase II completed on one or both sessions.
Updated patch attached:
git am -s 0001-Fix-driver-name-mismatch-between-32-bit-ODBC-app-and.patch
or pull my branch, above.
--
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
Attachments:
0001-Fix-driver-name-mismatch-between-32-bit-ODBC-app-and.patch (text/x-patch, 4.4K) download
From 85e208db45cd675d69aad44a95f8c79854682f5f Mon Sep 17 00:00:00 2001
From: Craig Ringer <craig@2ndquadrant.com>
Date: Wed, 25 Jun 2014 15:17:00 +0800
Subject: [PATCH] Fix driver name mismatch between 32-bit ODBC app and 64-bit
MSDTC host
If the 32-bit driver runs on a 64-bit host within a 32-bit app
running under SysWow64 then XA transactions will fail to recover.
That's because recovery is done by pgxalib.dll which runs within
MSDTC.exe - a 64-bit application. It connects to a DSN supplied
by psqlODBC in EnlistInDtc_1pipe during DTC enlistment by the
XA resource manager. This DSN uses the driver name of the client's
ODBC driver - which is fine so long as the client and MSDTC
architectures match. If they don't then MSDTC will fail to connect
to Pg, so it'll never resolve transactions.
Traces of MSDTC will show RM_COMMIT_DELIVERY_FAILED_DUE_TO_CONNECTION_DOWN
events.
Traces of pgxalib.dll will show xa_recover(..) being entered, followed by
"SQLDriverConnect return=-1".
To fix this, we detect if we're running under SysWow64 by examining the
PROCESSOR_ARCHITEW6432 environment variable and supply the 64-bit driver name
if so.
See mailing list thread:
http://www.postgresql.org/message-id/53A45B59.70303@2ndquadrant.com
for details.
Craig Ringer
---
connection.c | 46 ++++++++++++++++++++++++++++++++++++++++++++--
psqlodbc.h | 8 ++++++--
2 files changed, 50 insertions(+), 4 deletions(-)
diff --git a/connection.c b/connection.c
index 794ddde..3aeb71a 100644
--- a/connection.c
+++ b/connection.c
@@ -4362,10 +4362,52 @@ const char *CurrCatString(const ConnectionClass *conn)
DLL_DECLARE void PgDtc_create_connect_string(void *self, char *connstr, int strsize)
{
ConnectionClass *conn = (ConnectionClass *) self;
-
+ SYSTEM_INFO si;
ConnInfo *ci = &(conn->connInfo);
+ const char *drivername = ci->drivername;
+
+#if defined(_WIN32) && !defined(_WIN64)
+ /*
+ * If this is an x86 driver running on an x64 host then the driver name
+ * passed to MSDTC must be the (x64) driver but the client app will be
+ * using the 32-bit driver name. So MSDTC.exe will fail to find the driver
+ * and we'll fail to recover XA transactions.
+ *
+ * IsWow64Process(...) would be the ideal function for this, but is only
+ * available on Windows 6+ (Vista/2k8). We'd use GetNativeSystemInfo, which
+ * is supported on XP and 2k3, instead, but that won't link with older
+ * SDKs.
+ *
+ * It's impler to just test the PROCESSOR_ARCHITEW6432 environment
+ * variable.
+ *
+ * See http://www.postgresql.org/message-id/53A45B59.70303@2ndquadrant.com
+ * for details on this issue.
+ */
+ const char * const procenv = getenv("PROCESSOR_ARCHITEW6432");
+ if (procenv != NULL && strcmp(procenv, "AMD64") == 0)
+ {
+ /*
+ * We're a 32-bit binary running under SysWow64 on a 64-bit host and need
+ * to pass a different driver name.
+ *
+ * To avoid playing memory management games, just return a different
+ * string constant depending on the unicode-ness of the driver.
+ *
+ * It probably doesn't matter whether we use the Unicode or ANSI driver
+ * for the XA transaction manager, but pick the same as the client driver
+ * to keep things as similar as possible.
+ */
+#ifdef UNICODE_SUPPORT
+ drivername = DBMS_NAME_UNICODE"(x64)";
+#else
+ drivername = DBMS_NAME_ANSI"(x64)";
+#endif
+ }
+#endif // _WIN32 && !_WIN64
+
snprintf(connstr, strsize, "DRIVER={%s};SERVER=%s;PORT=%s;DATABASE=%s;UID=%s;PWD=%s;" ABBR_SSLMODE "=%s",
- ci->drivername, ci->server, ci->port, ci->database, ci->username, SAFE_NAME(ci->password), ci->sslmode);
+ drivername, ci->server, ci->port, ci->database, ci->username, SAFE_NAME(ci->password), ci->sslmode);
}
DLL_DECLARE void PgDtc_set_async(void *self, void *async)
diff --git a/psqlodbc.h b/psqlodbc.h
index c0c895f..05dcc9e 100644
--- a/psqlodbc.h
+++ b/psqlodbc.h
@@ -249,6 +249,10 @@ typedef double SDOUBLE;
/* Driver stuff */
#define DRIVERNAME "PostgreSQL ODBC"
+
+#define DBMS_NAME_UNICODE "PostgreSQL Unicode"
+#define DBMS_NAME_ANSI "PostgreSQL ANSI"
+
#if (ODBCVER >= 0x0300)
#if (ODBCVER >= 0x0351)
#define DRIVER_ODBC_VER "03.51"
@@ -257,9 +261,9 @@ typedef double SDOUBLE;
#endif /* ODBCVER 0x0351 */
#ifndef DBMS_NAME
#ifdef UNICODE_SUPPORT
-#define DBMS_NAME "PostgreSQL Unicode"
+#define DBMS_NAME DBMS_NAME_UNICODE
#else
-#define DBMS_NAME "PostgreSQL ANSI"
+#define DBMS_NAME DBMS_NAME_ANSI
#endif /* UNICODE_SUPPORT */
#endif /* DBMS_NAME */
#else
--
1.9.0
^ permalink raw reply [nested|flat] 11+ messages in thread
end of thread, other threads:[~2014-06-26 08:23 UTC | newest]
Thread overview: 11+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2014-06-20 16:03 msdtc with 32-bit app fails to resolve in-doubt or not-notifed transactions Craig Ringer <craig@2ndquadrant.com>
2014-06-20 21:34 ` Inoue, Hiroshi <inoue@tpf.co.jp>
2014-06-21 04:52 ` Craig Ringer <craig@2ndquadrant.com>
2014-06-21 08:02 ` Craig Ringer <craig@2ndquadrant.com>
2014-06-23 00:34 ` Inoue, Hiroshi <inoue@tpf.co.jp>
2014-06-23 01:23 ` Craig Ringer <craig@2ndquadrant.com>
2014-06-23 21:23 ` Inoue, Hiroshi <inoue@tpf.co.jp>
2014-06-24 03:07 ` Craig Ringer <craig@2ndquadrant.com>
2014-06-25 14:26 ` Craig Ringer <craig@2ndquadrant.com>
2014-06-26 08:23 ` Craig Ringer <craig@2ndquadrant.com>
2014-06-25 16:13 Re: msdtc with 32-bit app fails to resolve in-doubt or not-notifed transactions Craig Ringer <craig@2ndquadrant.com>
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