Re: [HACKERS] PostgreSQL 7.4devel - LOG: PGSTAT: socket() failed: Invalid argument

2003-07-09 Thread qhwt
Hello,

 On Mon, Jul 07, 2003 at 12:55:06AM +0900, [EMAIL PROTECTED] wrote:
  
  When hints.ai_family is PF_UNSPEC, getaddrinfo() returns two entries,
  first one being IPv6 one, and the second one is IPv4 one, even if
  IPv6 support is not compiled in the kernel(this is true at least on
  my FreeBSD box).

Sorry, this turned out to be bogus; AI_ADDRCONFIG flag was already present as
early as FreeBSD 4.3-RELEASE, but I forgot adding the flag in my test code.
The flag is not documented in the getaddrinfo(3) man page.

On Sun, Jul 06, 2003 at 06:35:52PM +0200, Kurt Roeckx wrote:
 And that is why you have AI_ADDRCONFIG, which seems to be broken
 for him.

I doubt RedHat 6 or MacOS X really support AI_ADDRCONFIG. Is it actually
defined somewhere in the system headers? Anyway it seems like its absence
is hidden by the following lines:

src/include/libpq/pqcomm.h:
85-/* Some systems don't have it, so default it to 0 so it doesn't
86- * have any effect on those systems. */
87:#ifndef  AI_ADDRCONFIG
88:#define  AI_ADDRCONFIG 0
89-#endif

---(end of broadcast)---
TIP 2: you can get off all lists at once with the unregister command
(send unregister YourEmailAddressHere to [EMAIL PROTECTED])


Re: [HACKERS] PostgreSQL 7.4devel - LOG: PGSTAT: socket() failed: Invalid argument

2003-07-06 Thread qhwt
On Mon, Jul 07, 2003 at 12:38:57AM +0900, [EMAIL PROTECTED] wrote:
 Hi,
 
 On Wed, Jul 02, 2003 at 03:49:19PM +0900, Kenji Sugita wrote:
  It seems that a value of addr-ai_socktype returned by getaddrinfo in
  pg_stat.c is not SOCK_DGRAM.
 
 Please try the following untested patch:

No, please disregard the previous mail and try this one.

When hints.ai_family is PF_UNSPEC, getaddrinfo() returns two entries,
first one being IPv6 one, and the second one is IPv4 one, even if
IPv6 support is not compiled in the kernel(this is true at least on
my FreeBSD box).

--- pgstat.cThu Jun 12 16:36:51 2003
+++ pgstat.cMon Jul  7 00:49:07 2003
@@ -145,7 +145,7 @@
 pgstat_init(void)
 {
ACCEPT_TYPE_ARG3alen;
-   struct  addrinfo*addr, hints;
+   struct  addrinfo*addr0, addr, hints;
int ret;
 
/*
@@ -187,17 +187,19 @@
hints.ai_addr = NULL;
hints.ai_canonname = NULL;
hints.ai_next = NULL;
-   ret = getaddrinfo2(localhost, NULL, hints, addr);
-   if (ret || !addr)
+   ret = getaddrinfo2(localhost, NULL, hints, addr0);
+   if (ret || !addr0)
{
elog(LOG, PGSTAT: getaddrinfo2() failed: %s,
gai_strerror(ret));
goto startup_failed;
}
-   
-   if ((pgStatSock = socket(addr-ai_family,
-   addr-ai_socktype, addr-ai_protocol))  0)
-   {
+
+   for (addr = addr0; addr != NULL; addr = addr-ai_next)
+   if ((pgStatSock = socket(addr-ai_family,
+   addr-ai_socktype, addr-ai_protocol)) = 0)
+   break;
+   if (pgStatSock  0) {
elog(LOG, PGSTAT: socket() failed: %m);
goto startup_failed;
}
@@ -211,8 +213,8 @@
elog(LOG, PGSTAT: bind() failed: %m);
goto startup_failed;
}
-   freeaddrinfo2(hints.ai_family, addr);
-   addr = NULL;
+   freeaddrinfo2(hints.ai_family, addr0);
+   addr0 = addr = NULL;
 
alen = sizeof(pgStatAddr);
if (getsockname(pgStatSock, (struct sockaddr *)pgStatAddr, alen)  0)



---(end of broadcast)---
TIP 8: explain analyze is your friend


Re: [HACKERS] PostgreSQL 7.4devel - LOG: PGSTAT: socket() failed: Invalid argument

2003-07-06 Thread Kurt Roeckx
On Mon, Jul 07, 2003 at 12:38:57AM +0900, [EMAIL PROTECTED] wrote:
 
 On Wed, Jul 02, 2003 at 03:49:19PM +0900, Kenji Sugita wrote:
  It seems that a value of addr-ai_socktype returned by getaddrinfo in
  pg_stat.c is not SOCK_DGRAM.
 
 Please try the following untested patch:
[...]

 + for (; addr != NULL; addr = addr-ai_next)
 + if ((pgStatSock = socket(addr-ai_family,
 + addr-ai_socktype, addr-ai_protocol)) = 0)
 + break;

This will break.  You should use a pointer to the addr, and go
over the list using that.

freeaddrinfo() needs to have the original addr back.

He seems to have 2 problems:
- On Mac OS X getaddrinfo() returns something it shouldn't.
  A patch like that could fix it.
- On Linux Redhat 6.2 (and 6.0) getaddrinfo() seems to have a
  problem with AI_ADDRCONFIG.  Which is also used in
  StreamServerPort().  So he won't be able to listen to any
  socket there either.

Not being able to use AI_ADDRCONFIG is rather annoying, but I
guess if we just try all the returned addresses until 1 works
will have to do.

Try the attached patch instead.


Kurt

Index: ./src/backend/postmaster/pgstat.c
===
RCS file: /projects/cvsroot/pgsql-server/src/backend/postmaster/pgstat.c,v
retrieving revision 1.37
diff -u -r1.37 pgstat.c
--- ./src/backend/postmaster/pgstat.c   12 Jun 2003 07:36:51 -  1.37
+++ ./src/backend/postmaster/pgstat.c   6 Jul 2003 16:27:20 -
@@ -146,6 +146,7 @@
 {
ACCEPT_TYPE_ARG3alen;
struct  addrinfo*addr, hints;
+   struct  addrinfo*addrp;
int ret;
 
/*
@@ -188,15 +189,38 @@
hints.ai_canonname = NULL;
hints.ai_next = NULL;
ret = getaddrinfo2(localhost, NULL, hints, addr);
-   if (ret || !addr)
+
+   addrp = addr;
+
+#ifdef HAVE_UNIX_SOCKETS
+   /* Skip AF_UNIX sockets. */
+   if (!ret)
+   {
+   while (addrp  addrp-ai_family == AF_UNIX)
+   {
+   addrp = addrp-ai_next;
+   }
+   }
+#endif
+
+   if (ret || !addrp)
{
elog(LOG, PGSTAT: getaddrinfo2() failed: %s,
gai_strerror(ret));
goto startup_failed;
}
+

-   if ((pgStatSock = socket(addr-ai_family,
-   addr-ai_socktype, addr-ai_protocol))  0)
+   for (; addrp; addrp = addrp-ai_next)
+   {
+   if ((pgStatSock = socket(addrp-ai_family,
+   addrp-ai_socktype, addrp-ai_protocol)) = 0)
+   {
+   break;
+   }
+   }
+
+   if (!addrp)
{
elog(LOG, PGSTAT: socket() failed: %m);
goto startup_failed;
@@ -206,7 +230,7 @@
 * Bind it to a kernel assigned port on localhost and get the assigned
 * port via getsockname().
 */
-   if (bind(pgStatSock, addr-ai_addr, addr-ai_addrlen)  0)
+   if (bind(pgStatSock, addrp-ai_addr, addrp-ai_addrlen)  0)
{
elog(LOG, PGSTAT: bind() failed: %m);
goto startup_failed;
Index: ./src/backend/libpq/pqcomm.c
===
RCS file: /projects/cvsroot/pgsql-server/src/backend/libpq/pqcomm.c,v
retrieving revision 1.157
diff -u -r1.157 pqcomm.c
--- ./src/backend/libpq/pqcomm.c12 Jun 2003 07:36:51 -  1.157
+++ ./src/backend/libpq/pqcomm.c6 Jul 2003 16:28:01 -
@@ -216,7 +216,7 @@
/* Initialize hint structure */
MemSet(hint, 0, sizeof(hint));
hint.ai_family = family;
-   hint.ai_flags = AI_PASSIVE | AI_ADDRCONFIG;
+   hint.ai_flags = AI_PASSIVE;
hint.ai_socktype = SOCK_STREAM;
 
 #ifdef HAVE_UNIX_SOCKETS

---(end of broadcast)---
TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]


Re: [HACKERS] PostgreSQL 7.4devel - LOG: PGSTAT: socket() failed: Invalid argument

2003-07-06 Thread Kurt Roeckx
On Mon, Jul 07, 2003 at 12:55:06AM +0900, [EMAIL PROTECTED] wrote:
 
 When hints.ai_family is PF_UNSPEC, getaddrinfo() returns two entries,
 first one being IPv6 one, and the second one is IPv4 one, even if
 IPv6 support is not compiled in the kernel(this is true at least on
 my FreeBSD box).

And that is why you have AI_ADDRCONFIG, which seems to be broken
for him.


Kurt


---(end of broadcast)---
TIP 2: you can get off all lists at once with the unregister command
(send unregister YourEmailAddressHere to [EMAIL PROTECTED])


Re: [HACKERS] PostgreSQL 7.4devel - LOG: PGSTAT: socket() failed: Invalid argument

2003-07-06 Thread Kurt Roeckx
On Sun, Jul 06, 2003 at 06:30:04PM +0200, Kurt Roeckx wrote:
 Try the attached patch instead.

Oops, that one was a little broken. I change it.

Try the attached one instead.


Kurt

Index: ./src/backend/postmaster/pgstat.c
===
RCS file: /projects/cvsroot/pgsql-server/src/backend/postmaster/pgstat.c,v
retrieving revision 1.37
diff -u -r1.37 pgstat.c
--- ./src/backend/postmaster/pgstat.c   12 Jun 2003 07:36:51 -  1.37
+++ ./src/backend/postmaster/pgstat.c   6 Jul 2003 16:42:52 -
@@ -145,7 +145,7 @@
 pgstat_init(void)
 {
ACCEPT_TYPE_ARG3alen;
-   struct  addrinfo*addr, hints;
+   struct  addrinfo*addrs, *addr, hints;
int ret;
 
/*
@@ -187,16 +187,32 @@
hints.ai_addr = NULL;
hints.ai_canonname = NULL;
hints.ai_next = NULL;
-   ret = getaddrinfo2(localhost, NULL, hints, addr);
-   if (ret || !addr)
+   ret = getaddrinfo2(localhost, NULL, hints, addrs);
+
+   if (ret || !addrs)
{
elog(LOG, PGSTAT: getaddrinfo2() failed: %s,
gai_strerror(ret));
goto startup_failed;
}

-   if ((pgStatSock = socket(addr-ai_family,
-   addr-ai_socktype, addr-ai_protocol))  0)
+   for (addr = addrs; addr; addr = addr-ai_next)
+   {
+#ifdef HAVE_UNIX_SOCKETS
+   /* Skip AF_UNIX sockets. */
+   while (addr  addr-ai_family == AF_UNIX)
+   {
+   continue;
+   }
+#endif
+   if ((pgStatSock = socket(addr-ai_family,
+   addr-ai_socktype, addr-ai_protocol)) = 0)
+   {
+   break;
+   }
+   }
+
+   if (!addr || pgStatSock  0)
{
elog(LOG, PGSTAT: socket() failed: %m);
goto startup_failed;
@@ -211,8 +227,8 @@
elog(LOG, PGSTAT: bind() failed: %m);
goto startup_failed;
}
-   freeaddrinfo2(hints.ai_family, addr);
-   addr = NULL;
+   freeaddrinfo2(hints.ai_family, addrs);
+   addrs = NULL;
 
alen = sizeof(pgStatAddr);
if (getsockname(pgStatSock, (struct sockaddr *)pgStatAddr, alen)  0)
@@ -257,9 +273,9 @@
return;
 
 startup_failed:
-   if (addr)
+   if (addrs)
{
-   freeaddrinfo2(hints.ai_family, addr);
+   freeaddrinfo2(hints.ai_family, addrs);
}
 
if (pgStatSock = 0)
Index: ./src/backend/libpq/pqcomm.c
===
RCS file: /projects/cvsroot/pgsql-server/src/backend/libpq/pqcomm.c,v
retrieving revision 1.157
diff -u -r1.157 pqcomm.c
--- ./src/backend/libpq/pqcomm.c12 Jun 2003 07:36:51 -  1.157
+++ ./src/backend/libpq/pqcomm.c6 Jul 2003 16:42:58 -
@@ -216,7 +216,7 @@
/* Initialize hint structure */
MemSet(hint, 0, sizeof(hint));
hint.ai_family = family;
-   hint.ai_flags = AI_PASSIVE | AI_ADDRCONFIG;
+   hint.ai_flags = AI_PASSIVE;
hint.ai_socktype = SOCK_STREAM;
 
 #ifdef HAVE_UNIX_SOCKETS

---(end of broadcast)---
TIP 4: Don't 'kill -9' the postmaster


Re: [HACKERS] PostgreSQL 7.4devel - LOG: PGSTAT: socket() failed: Invalid argument

2003-07-03 Thread Kurt Roeckx
On Thu, Jul 03, 2003 at 10:44:31AM +0900, Kenji Sugita wrote:
 
 From: Kurt Roeckx [EMAIL PROTECTED]
 To: Kenji Sugita [EMAIL PROTECTED]
 Cc: [EMAIL PROTECTED]
 Date: Wed, 2 Jul 2003 19:20:11 +0200
 
 ;;; What system are you running on, and does it have a getaddrinfo()
 ;;; or not?
 
 Red Hat Linux 6.2 and Mac OS X 10.2.6.
[...]
 For Mac OS X it produces LOG:  PGSTAT: socket() failed: Protocol not supported.

This looks a little broken behaviour to me.  My guess is that it
returns an AF_INET6 socket but doesn't support it in the kernel.
In that case with the AI_ADDRCONFIG option it shouldn't have
returned that address.  The question is wether your getaddrinfo()
supports that option, and wether it's working or not.

We can fix this by going over all the returned addresses until
one of the socket() calls works.

We probably should also skip AF_UNIX sockets, since that might
not be want we want.

 $ postmaster (on Red Hat)
 ...
 2003-07-03 10:19:38 [29761] LOG:  XX000: PGSTAT: getaddrinfo2() failed: Name or 
 service not known

That is just evil.  It can't even resolv localhost?  Do you have
a localhost entry in /etc/hosts?

If that's not the problem I see no other way but to use
INADDR_LOOPBACK and in6addr_loopback directly instead, which I
really hate.

 What value shuld be passed to a following socket call with
 addr-ai_socktype?
 
   pgstats.c  
 if ((pgStatSock = socket(addr-ai_family,
 addr-ai_socktype, addr-ai_protocol))  0)
 {
 elog(LOG, PGSTAT: socket() failed: %m);
 goto startup_failed;
 }

The ai_family should be either AF_INET or AF_INET6, ai_socktype
should be SOCK_DGRAM, and ai_protocol 0 or IPPROTO_UDP.



Kurt


---(end of broadcast)---
TIP 3: if posting/reading through Usenet, please send an appropriate
  subscribe-nomail command to [EMAIL PROTECTED] so that your
  message can get through to the mailing list cleanly


Re: [HACKERS] PostgreSQL 7.4devel - LOG: PGSTAT: socket() failed: Invalid argument

2003-07-02 Thread Kurt Roeckx
On Wed, Jul 02, 2003 at 03:49:19PM +0900, Kenji Sugita wrote:
 It seems that a value of addr-ai_socktype returned by getaddrinfo in
 pg_stat.c is not SOCK_DGRAM.

What system are you running on, and does it have a getaddrinfo()
or not?

If I tell getaddrinfo() it should return a SOCK_DGRAM, it can
only mean that getaddrinfo() is broken.


Kurt


---(end of broadcast)---
TIP 8: explain analyze is your friend


Re: [HACKERS] PostgreSQL 7.4devel - LOG: PGSTAT: socket() failed: Invalid argument

2003-07-02 Thread Kurt Roeckx
On Wed, Jul 02, 2003 at 03:49:19PM +0900, Kenji Sugita wrote:
 It seems that a value of addr-ai_socktype returned by getaddrinfo in
 pg_stat.c is not SOCK_DGRAM.

What do you base this on?

My guess is that it returns an ipv6 address while you do not have
IPv6 support in the kernel.  If that is the case, the attached
patch should fix it.



Kurt

Index: src/backend/postmaster/pgstat.c
===
RCS file: /projects/cvsroot/pgsql-server/src/backend/postmaster/pgstat.c,v
retrieving revision 1.37
diff -u -r1.37 pgstat.c
--- src/backend/postmaster/pgstat.c 12 Jun 2003 07:36:51 -  1.37
+++ src/backend/postmaster/pgstat.c 2 Jul 2003 18:34:30 -
@@ -179,7 +179,7 @@
/*
 * Create the UDP socket for sending and receiving statistic messages
 */
-   hints.ai_flags = AI_PASSIVE;
+   hints.ai_flags = AI_PASSIVE | AI_ADDRCONF;
hints.ai_family = PF_UNSPEC;
hints.ai_socktype = SOCK_DGRAM;
hints.ai_protocol = 0;

---(end of broadcast)---
TIP 4: Don't 'kill -9' the postmaster


Re: [HACKERS] PostgreSQL 7.4devel - LOG: PGSTAT: socket() failed: Invalid argument

2003-07-02 Thread Kurt Roeckx
On Wed, Jul 02, 2003 at 08:35:00PM +0200, Kurt Roeckx wrote:
 On Wed, Jul 02, 2003 at 03:49:19PM +0900, Kenji Sugita wrote:
  It seems that a value of addr-ai_socktype returned by getaddrinfo in
  pg_stat.c is not SOCK_DGRAM.
 
 What do you base this on?
 
 My guess is that it returns an ipv6 address while you do not have
 IPv6 support in the kernel.  If that is the case, the attached
 patch should fix it.
 

Oops typo, fixed in new attachment.


Kurt

Index: src/backend/postmaster/pgstat.c
===
RCS file: /projects/cvsroot/pgsql-server/src/backend/postmaster/pgstat.c,v
retrieving revision 1.37
diff -u -r1.37 pgstat.c
--- src/backend/postmaster/pgstat.c 12 Jun 2003 07:36:51 -  1.37
+++ src/backend/postmaster/pgstat.c 2 Jul 2003 18:51:08 -
@@ -179,7 +179,7 @@
/*
 * Create the UDP socket for sending and receiving statistic messages
 */
-   hints.ai_flags = AI_PASSIVE;
+   hints.ai_flags = AI_PASSIVE | AI_ADDRCONFIG;
hints.ai_family = PF_UNSPEC;
hints.ai_socktype = SOCK_DGRAM;
hints.ai_protocol = 0;

---(end of broadcast)---
TIP 9: the planner will ignore your desire to choose an index scan if your
  joining column's datatypes do not match