Re: 8.2.3: Server crashes on Windows using Eclipse/Junit - Mailing list pgsql-general

From Dave Page
Subject Re: 8.2.3: Server crashes on Windows using Eclipse/Junit
Date
Msg-id 471E19F9.3070709@postgresql.org
Whole thread Raw
In response to Re: 8.2.3: Server crashes on Windows using Eclipse/Junit  ("Harald Armin Massa" <haraldarminmassa@gmail.com>)
List pgsql-general
Harald Armin Massa wrote:
> Dave,
>
>> It's coming from direct dependencies on user32.dll (from which we use
>> wsprintf()) and shell32.dll (from which we use SHGetSpecialFolderPath())
>> and is allocated when ResumeThread() is called to kickstart the new
>> backend,
>
> why does every backend need its own heap for user32.dll or
> shell32.dll? Wasn't the point of shared dlls to be shared?

No idea, and I thought so.

It's quite easy to prove using the test program attached. Just monitor
the desktop heap with dheapmon (from Microsoft's website), and run the
program with a single command line argument to get it to spawn a 100
child processes. You can stop it loading various DLLs by commenting out
the dummy calls to functions in them and rebuilding.

Of course, none of this would be an issue if we made the backend
multithreaded. :-)

I'll get my coat...

/D

#include <stdio.h>
#include <Windows.h>
#include <winsock.h>
#define SECURITY_WIN32
#include <Security.h>
#include <shlobj.h>

int main(int argc, char *argv[])
{
    // Dummy functions to force linking to specific libs

    // user32.lib
    IsCharAlpha('a');

    // wsock32.lib
    WSADATA    wsaData;
    WSAStartup(MAKEWORD(1, 1), &wsaData);

    // secur32.lib
    char un[30];
    DWORD dwUNLen = 30;
    GetUserNameExA(NameUserPrincipal, un, &dwUNLen);

    // advapi32.dll
    char un2[30];
    DWORD dwUN2Len = 30;
    GetUserNameA(un2, &dwUN2Len);

    // shell32.dll
    IsUserAnAdmin();

    // Used by child processes
    if (argc == 1)
    {
        while (1)
        {
            printf("Foo\n");
            Sleep(2000);
        }
    }
    else
    {
        for (int x=0; x<100; x++)
        {
            STARTUPINFOA si;
            PROCESS_INFORMATION pi;

            memset(&pi, 0, sizeof(pi));
            memset(&si, 0, sizeof(si));
            si.cb = sizeof(si);

            /*
             * Create the subprocess in a suspended state. This will be resumed later,
             * once we have written out the parameter file.
             */
            printf("Creating process %d...\n", x);
            if (!CreateProcessA(NULL, argv[0], NULL, NULL, TRUE, CREATE_SUSPENDED,
                               NULL, NULL, &si, &pi))
            {
                printf("CreateProcess call failed: %m (error code %d)", (int) GetLastError());
                return -1;
            }

            printf("Resuming thread %d...\n", x);
            if (ResumeThread(pi.hThread) == -1)
            {
                if (!TerminateProcess(pi.hProcess, 255))
                {
                    printf("could not terminate unstartable process: error code %d", (int) GetLastError());
                    CloseHandle(pi.hProcess);
                    CloseHandle(pi.hThread);
                    return -1;
                }
                CloseHandle(pi.hProcess);
                CloseHandle(pi.hThread);
                printf("could not resume thread of unstarted process: error code %d", (int) GetLastError());
                return -1;
            }
        }
    }

    return 0;
}


pgsql-general by date:

Previous
From: Gregory Stark
Date:
Subject: Re: 8.2.3: Server crashes on Windows using Eclipse/Junit
Next
From: "Harald Armin Massa"
Date:
Subject: Re: 8.2.3: Server crashes on Windows using Eclipse/Junit