Thread: BUG #6201: Windows User Log Off Causes Backend Exception 0xC0000142

BUG #6201: Windows User Log Off Causes Backend Exception 0xC0000142

From
"Jerome Schulteis"
Date:
The following bug has been logged online:

Bug reference:      6201
Logged by:          Jerome Schulteis
Email address:      jerome.schulteis@edstrom.com
PostgreSQL version: 9.0.4
Operating system:   Windows XP Pro SP3
Description:        Windows User Log Off Causes Backend Exception 0xC0000142
Details:

It does not happen on every log off, but if the Windows console user logs
off
of the server at just the wrong time while a backend is starting up, the
backend terminates with exception 0xC0000142 (STATUS_DLL_INIT_FAILED), and
the
PostgreSQL Windows service stops (shared memory block is still in use):

2011-09-09 10:34:01 CDT LOG:  server process (PID 3260) was terminated by
exception 0xC0000142
2011-09-09 10:34:01 CDT HINT:  See C include file "ntstatus.h" for a
description of the hexadecimal value.
2011-09-09 10:34:01 CDT LOG:  terminating any other active server processes
[...]
2011-09-09 10:34:02 CDT WARNING:  terminating connection because of crash of
another server process
2011-09-09 10:34:02 CDT DETAIL:  The postmaster has commanded this server
process to roll back the current transaction and exit, because another
server process exited abnormally and possibly corrupted shared memory.
2011-09-09 10:34:02 CDT HINT:  In a moment you should be able to reconnect
to the database and repeat your command.
2011-09-09 10:34:02 CDT LOG:  all server processes terminated;
reinitializing
2011-09-09 10:34:12 CDT FATAL:  pre-existing shared memory block is still in
use
2011-09-09 10:34:12 CDT HINT:  Check if there are any old server processes
still running, and terminate them.

Originally encountered with our web app running a stress test on PostgreSQL
8.4.2; I reproduced it on a default one-click install of 9.0.4.  I run the
following Java on a separate machine to get a new connection every 100 ms:

class ConnectionHog {
    static public void main(String[] args) {
        try {
            while (true) {
                java.sql.DriverManager.getConnection(args[0], args[1],
args[2]);
                Thread.sleep(Long.parseLong(args[3]));
            }
        }
        catch (Throwable t) {
            System.err.println(t);
        }
    }
}

I then log on and off the server from a separate user account (that is, not
the postgres
account); the error shows up after at most 3 log offs. As long as no log
offs happen on the server, no problem.

Re: BUG #6201: Windows User Log Off Causes Backend Exception 0xC0000142

From
Craig Ringer
Date:
On 10/09/2011 4:59 AM, Jerome Schulteis wrote:
> The following bug has been logged online:
>
> Bug reference:      6201
> Logged by:          Jerome Schulteis
> Email address:      jerome.schulteis@edstrom.com
> PostgreSQL version: 9.0.4
> Operating system:   Windows XP Pro SP3
> Description:        Windows User Log Off Causes Backend Exception 0xC0000142
> Details:
>
> It does not happen on every log off, but if the Windows console user logs
> off
> of the server at just the wrong time while a backend is starting up, the
> backend terminates with exception 0xC0000142 (STATUS_DLL_INIT_FAILED), and
> the
> PostgreSQL Windows service stops (shared memory block is still in use):
I wonder which DLL failed? It seems that PostgreSQL doesn't print the
message the operating system generates for these errors. For example, it
should be printing:

"{DLL Initialization Failed} Initialization of the dynamic link library
%hs failed. The process is terminating abnormally."

... where %hs is the DLL name or path. I should have a play with that
once I finish moving house...



Do you have any antivirus or antimalware products on the system?

Do you have a Logitech webcam? Their webcam effects app adds a hook DLL
to every process on the system, and I've seen it cause issues with MinGW
among other things before.

If you launch a trivial process like "notepad.exe" then launch Process
Explorer from SysInternals, select notepad.exe and press control-D to
show the DLL list, what non-Microsoft DLLs are shown? You can copy and
paste the list.

If you examine a running postgres.exe backend (one of the processess
listed UNDER the main "postgres.exe" which is the postmaster) the same
way, what non-Microsoft DLLs are shown there? Note that you may have to
run Process Explorer as administrator to view the DLL list for
postgres.exe. Ignore any DLLs ending in ".NLS" .

For bonus points, verify each Microsoft DLL as having a valid signature
by double-clicking on it in the list, and report any DLLs that fail
verification.



--
Craig Ringer

Re: BUG #6201: Windows User Log Off Causes Backend Exception 0xC0000142

From
Craig Ringer
Date:
On 12/09/2011 11:02 PM, Jerome Schulteis wrote:
>
> For bonus points, verify each Microsoft DLL as having a valid signature
> by double-clicking on it in the list, and report any DLLs that fail
> verification.
> All Microsoft DLLs verified. The following are all of the non-Microsoft non-.nls DLLs:
>
> iconv.dll    LGPLed libiconv for Windows NT/2000/XP and Windows 95/98/ME    Free Software Foundation    1.9.0.0
> libeay32.dll    OpenSSL Shared Library    The OpenSSL Project, http://www.openssl.org/    0.9.8.12
> libiconv-2.dll    LGPLed libiconv for Windows NT/2000/XP/Vista and Windows 95/98/ME    Free Software Foundation
1.12.0.0
> libintl-8.dll    LGPLed libintl for Windows NT/2000/XP/Vista and Windows 95/98/ME    Free Software Foundation
0.17.0.0
> libxml2.dll
> postgres.exe    PostgreSQL Server    PostgreSQL Global Development Group    9.0.4.11104
> ssleay32.dll    OpenSSL Shared Library    The OpenSSL Project, http://www.openssl.org/    0.9.8.12
> zlib1.dll    zlib data compression library        1.2.3.0

Damn, scratch that theory. It's not a buggy hook DLL with some kind of race.

Maybe this exists in the standard Pg distribution and people don't
usually hit it because there aren't usually user logon/logoff events on
most database servers while they're doing work? Or people who've noticed
it have never bothered to track it down and isolate it until you did?

It sounds like you've tested this on a clean Windows install in a VM, yes?

The next step would be to figure out which DLL's InitInstance() or
ExitInstance() is failing, and how to get the postmaster to print the
formatted version of that error so we can see the substitutions in the
message string. I'm not able to take that on right now as I'm behind on
my main work and moving house as well.

Is anyone willing to volunteer to dig into this one?

--
Craig Ringer

Re: BUG #6201: Windows User Log Off Causes Backend Exception 0xC0000142

From
Jerome Schulteis
Date:
PiBGcm9tOiBDcmFpZyBSaW5nZXIgW21haWx0bzpyaW5nZXJjQHJpbmdlcmMu
aWQuYXVdDQo+IFNlbnQ6IEZyaWRheSwgU2VwdGVtYmVyIDA5LCAyMDExIDc6
NTMgUE0NCj4gDQo+IE9uIDEwLzA5LzIwMTEgNDo1OSBBTSwgSmVyb21lIFNj
aHVsdGVpcyB3cm90ZToNCj4gPiBUaGUgZm9sbG93aW5nIGJ1ZyBoYXMgYmVl
biBsb2dnZWQgb25saW5lOg0KPiA+DQo+ID4gQnVnIHJlZmVyZW5jZTogICAg
ICA2MjAxDQo+ID4gTG9nZ2VkIGJ5OiAgICAgICAgICBKZXJvbWUgU2NodWx0
ZWlzDQo+ID4gRW1haWwgYWRkcmVzczogICAgICBqZXJvbWUuc2NodWx0ZWlz
QGVkc3Ryb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