Re: statistics process shutting down - Mailing list pgsql-hackers-win32

From Merlin Moncure
Subject Re: statistics process shutting down
Date
Msg-id 6EE64EF3AB31D5448D0007DD34EEB3412A7545@Herge.rcsinc.local
Whole thread Raw
In response to statistics process shutting down  ("Merlin Moncure" <merlin.moncure@rcsonline.com>)
Responses Re: statistics process shutting down
List pgsql-hackers-win32
> 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

pgsql-hackers-win32 by date:

Previous
From: Tom Lane
Date:
Subject: Re: statistics process shutting down
Next
From: Tom Lane
Date:
Subject: Re: statistics process shutting down