Re: statistics process shutting down

"Merlin Moncure" <[email protected]>
Newsgroups gmane.comp.db.postgresql.devel.win32
Message-ID <[email protected]>
> Evidently coming from here:
> 
>         len = piperead(readPipe, ((char *) &msg) + nread,
>                        targetlen - nread);
>         if (len < 0)
>         {
>             if (errno == EINTR)
>                 continue;
>             ereport(ERROR,
>                     (errcode_for_socket_access(),
>                      errmsg("could not read from statistics collector
> pipe: %m")));
>         }
> 
> So why is piperead() failing, and why doesn't it set errno to
something
> useful?

Well, the win32 piperead() is really just a call to recv() (vs unix
read()).  Here is the win32 implemenation:
int
piperead(int s, char *buf, int len)
{
	int			ret = recv(s, buf, len, 0);

	if (ret < 0 && WSAGetLastError() == WSAECONNRESET)
		/* EOF on the pipe! (win32 socket based implementation)
*/
		ret = 0;
	return ret;
}

I think the key to this puzzle is the return code from
WSAGetLastError().  Also, the WSA call *might* be masking the value of
errno.  I did a quick search and came up with this:
http://archives.postgresql.org/pgsql-patches/2001-10/msg00160.php

I think maybe errno needs to get set to WSAGetLastError().  In pipe.c:

if (ret < 0)
{
   int  wsa_errno;
   wsa_errno = WSAGetLastError();

   if (WSAECONNRESET == wsa_errno)
   {   /* EOF on the pipe! (win32 socket based implementation) */
      ret = 0;
   }
   else
   {
      errno = wsa_errno;  /* this *might* be ok */
   }
}

return ret;

Maybe Magnus might comment here.  This doesn't explain why the read call
is failing but I'm pretty sure the error code is not being properly
returned.

Merlin

---------------------------(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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.