Re: Why doesn't src/backend/port/win32/socket.c implement bind()?

From: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Magnus Hagander <magnus(at)hagander(dot)net>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Why doesn't src/backend/port/win32/socket.c implement bind()?
Date: 2016-04-14 00:38:40
Message-ID: CAB7nPqQhnyiqR-oz7MZ4X4O1o0=v4KYjpcyogMmRtAV46LR3Bw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Thu, Apr 14, 2016 at 8:46 AM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> Alvaro Herrera <alvherre(at)2ndquadrant(dot)com> writes:
>> Michael Paquier wrote:
>>> Well, yes. That's true, we could do without. Even if this could give
>>> an indication about a node running, as long as a port has been
>>> associated to a node once, we just need to be sure that a new port is
>>> not allocated. On Windows, I am not sure that it is worth the
>>> complication to be honest, and the current code gives a small safety
>>> net, which is better than nothing.
>
>> If we need to fix the test so that it works in a wider environment for
>> Windows, I don't think it makes sense to remove anything -- rather we
>> should change the test as Tom suggests to verify that the port is really
>> free rather than just doing the pg_isready test. Maybe the additional
>> test will be useless in non-Windows environment, but why cares? It will
>> work all the same.
>
> I think Michael is arguing that it's not worth fixing. He might be right;
> it's not like this is the only cause of irreproducible failures on the
> Windows critters. Still, it bugs me if we know how to make the regression
> tests more reliable and do not do so. Back when I packaged mysql for Red
> Hat, I was constantly annoyed by how often their tests failed under load.
> Don't want to be like that.

Some experiment is proving that it is actually not that complicated to
make that cross-platform:
use Socket;

my $remote = 'localhost';
my $port = 5432;
$iaddr = inet_aton($remote);
$paddr = sockaddr_in($port, $iaddr);
$proto = getprotobyname("tcp");
socket(SOCK, PF_INET, SOCK_STREAM, $proto) || die "socket: $!";
connect(SOCK, $paddr) || die "connect: $!";
close (SOCK) || die "close: $!";

IO::Socket::INET is another option, but I am not seeing it in perl <
5.12, and that's not part of ActivePerl, which makes life harder on
Windows. Socket is available on both. Does that address your concerns?
--
Michael

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andres Freund 2016-04-14 00:41:39 Re: Proposal: Generic WAL logical messages
Previous Message Stephen Frost 2016-04-14 00:24:38 Re: Reserved roles and user mapping