BUG #4060: libpq - large stack causes TCP/IP error

From: "Bruce Nairn" <bruce(dot)nairn(at)kingcounty(dot)gov>
To: pgsql-bugs(at)postgresql(dot)org
Subject: BUG #4060: libpq - large stack causes TCP/IP error
Date: 2008-03-25 22:32:09
Message-ID: 200803252232.m2PMW9Hx009065@wwwmaster.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs


The following bug has been logged online:

Bug reference: 4060
Logged by: Bruce Nairn
Email address: bruce(dot)nairn(at)kingcounty(dot)gov
PostgreSQL version: 8.3.1
Operating system: Windows XP Pro
Description: libpq - large stack causes TCP/IP error
Details:

I'm using the libpq interface on Win XP (x86) to connect to a postgreSQL
database. Compiling with microsoft Visual Studio 2005 (express edition).
When the program stack size increases past a certain size, PQsetdbLogin
returns a TCP/IP buffer error: could not connect to server: No buffer space
available (0x00002747/10055).

A sample code that reproduces the error is attached below.

Any suggestions or fixes would be appreciated.
Thanks,
Bruce

------------------------
#include <cstdio>
#include <string>
#include <iostream>

#include "libpq-fe.h"

/* ---------------------
* This is a test program to demonstrate problem connecting to a
PostgreSQL
* database when the stack is set to exceed approx 0x32cd0000
* (decimal: 852295680) seems to depend slightly on shell environment
*
* Compile on Windows XP with MS Visual Studio 2005:
* > cl /EHsc /MD /F0x33000000 testconn4.cpp
/Ic:\postgresql\postgresql-8.3.1\src\interfaces\libpq
* /Ic:\postgresql\postgresql-8.3.1\src\include
/Ic:\postgresql\postgresql-8.3.1\src
* /link
c:\postgresql\postgresql-8.3.1\src\interfaces\libpq\release\libpqdll.lib
*
* gives:
*
* >testconn4 guest 103
* start
* inputs first
* PQsetdbLogin
* Connection to database failed Error returned: could not connect to server:
No buffer space available (0x00002747/10055)
* Is the server running on host "store.cincomsmalltalk.com" and
accepting
* TCP/IP connections on port 5432?
*
* compile with /F0x32000000 (or smaller, or omit), gives expected
output:
*
* >testconn4 guest 103
* start
* inputs first
* PQsetdbLogin
* success!
*
* Is there a solution to allow this to work with a program that requires
* a stack this large?
*/

using namespace std;
extern "C" void LoadWaterBody(const char* user, const char* setnum){

std::string newuser = user;
std::string newsetnum = setnum;

PGconn* conn;
PGresult* pgrs;
char* pghost;
char* pgport;
char* pgoptions;
char* pgtty;
char* dbName;
char* login;
char* pwd;

/* ----------------
* Google found this database available for public connection, so I use it
for
* demonstration purposes... Thanks!
* http://www.cincomsmalltalk.com/CincomSmalltalkWiki/PostgreSQL+Access+Page#
guestAccess
*/

pghost="store.cincomsmalltalk.com";
pgport="5432";

pgoptions=NULL;
pgtty=NULL;

dbName="store_public";
login="guest";
pwd="guest";

cout << "inputs first\n";
conn = PQsetdbLogin(pghost, pgport, pgoptions, pgtty, dbName, login,
pwd);
cout << "PQsetdbLogin\n";

if (PQstatus(conn) == CONNECTION_BAD) { // did the database
connection fail?
cerr << "Connection to database failed "
<< "Error returned: " << PQerrorMessage(conn) << endl;
exit(1);
}

// normally db query would go here...

cout << "success!";
}

int main(int argc, const char* argv[] ) {
cout << "start\n";
LoadWaterBody (argv[1], argv[2]);
}

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2008-03-25 23:34:52 Re: Possible problem with EXTRACT(EPOCH FROM TIMESTAMP)
Previous Message Mark Steben 2008-03-25 21:13:32 BUG #4059: Vacuum full not always cleaning empty tables