[#1011408] Seeing address in use errors

View Trackers | Bugs | Download .csv | Monitor

Date:
2013-12-05 17:03
Priority:
3
State:
Open
Submitted by:
Elliott Anderson (elldawg)
Assigned to:
Nobody (None)
Category:
None
Group:
None
Resolution:
None
 
Summary:
Seeing address in use errors

Detailed description
I am working on a project that uses pgbouncer with postgres. The application generally works well, but occasionally we get the following error from a call to PQconnectdb:
could not connect to server: Address already in use (0x00002740/10048) ls the server running on host “127.0.0.1” and accepting
TCP/IP connections on port 6432?

So, I wrote the following program to test the limits of what pgbouncer would allow, and I get the same error after about 3900 connections.

int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
WinsockInit init; //class I wrote to manage winsock startup and cleanup
int nRetCode = 0;
PGconn * myconn = NULL;

// initialize MFC and print and error on failure
if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
{
// TODO: change error code to suit your needs
_tprintf(_T("Fatal Error: MFC initialization failed\n"));
nRetCode = 1;
}
else
{
UINT connCount = 0;
vector<PGconn*> cons;
while(true)
{
myconn = PQconnectdb("hostaddr = 127.0.0.1 dbname= CIC_FD user = postgres password = pgadm1,3,5,7 connect_timeout = 10");
if (myconn && PQstatus(myconn) != CONNECTION_OK)
{
CString error;
error.Format(_T("connection failed after %d tries with error:\n"), connCount);
//if(0 <= error.Find(_T("10048")))
_tprintf(error);
printf("%s\n", PQerrorMessage(myconn));
break;
}
else
{
cons.push_back(myconn);

if(cons.size() >= 99)
{
PQfinish(*cons.begin());
cons.erase(cons.begin());
}
++connCount;
}

//Sleep(25);
}

vector<PGconn*>::iterator it = cons.begin();
while(it != cons.end())
{
PQfinish(*it);
cons.erase(it);
it = cons.begin();
}

char str[255];
cin.getline(str, 255);
}

return nRetCode;
}

I am running on windows XP. It looks like we may be exhausting the dynamic ports, but we expect a different error code in that situation. We're looking for insight into how to avoid this error.

Followup

Message
Date: 2013-12-06 17:46
Sender: Elliott Anderson

using postgres 9.1
Date: 2013-12-06 17:45
Sender: Elliott Anderson

Using pgBouncer 1.5

Attached Files:

Changes:

No Changes Have Been Made to This Item

Powered By FusionForge