View Issue Details

IDProjectCategoryView StatusLast Update
0000207Pgpool-IIBugpublic2016-06-20 14:10
ReporterxlotluAssigned Tot-ishii 
PrioritynormalSeverityblockReproducibilityalways
Status resolvedResolutionopen 
PlatformLinuxOSOS Version
Product Version 
Target VersionFixed in Version 
Summary0000207: pgpool tries to bind twice to the listening socket on debian
Description$ sudo pgpool -n
2016-06-16 16:40:37: pid 900: WARNING: could not open configuration file: "pgpool.conf"
    
2016-06-16 16:40:37: pid 900: DETAIL: using default configuration parameter values
2016-06-16 16:40:37: pid 900: LOG: Setting up socket for 127.0.0.1:9999
2016-06-16 16:40:37: pid 900: LOG: Setting up socket for 127.0.0.1:9999
2016-06-16 16:40:37: pid 900: FATAL: failed to create INET domain socket
2016-06-16 16:40:37: pid 900: DETAIL: bind on socket failed with error "Address already in use"


This happens on debian testing. I get the same exact behaviour with the default debian package (3.4.3), and with versions 3.4.6 and 3.5.2. Running with the default configuration, it looks like indeed it's trying to bind() twice:

$ sudo strace -o test.txt pgpool -n 2>/dev/null; grep -A 4 -B 4 9999 test.txt
shmat(16351246, 0, 0) = 0x7f98ec5a0000
shmget(IPC_PRIVATE, 6144, IPC_CREAT|IPC_EXCL|0600) = 16384015
shmat(16384015, 0, 0) = 0x7f98ec59e000
socket(PF_LOCAL, SOCK_STREAM, 0) = 5
bind(5, {sa_family=AF_LOCAL, sun_path="/tmp/.s.PGSQL.9999"}, 110) = 0
chmod("/tmp/.s.PGSQL.9999", 0777) = 0
listen(5, 10000) = 0
socket(PF_LOCAL, SOCK_STREAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0) = 6
connect(6, {sa_family=AF_LOCAL, sun_path="/var/run/nscd/socket"}, 110) = -1 ENOENT (No such file or directory)
close(6) = 0
--
recvmsg(6, {msg_name(12)={sa_family=AF_NETLINK, pid=0, groups=00000000}, msg_iov(1)=[{"H\0\0\0\24\0\2\0\377\261bW\345\33\0\0\n\200\200\376\1\0\0\0\24\0\1\0\0\0\0\0"..., 4096}], msg_controllen=0, msg_flags=0}, 0) = 504
recvmsg(6, {msg_name(12)={sa_family=AF_NETLINK, pid=0, groups=00000000}, msg_iov(1)=[{"\24\0\0\0\3\0\2\0\377\261bW\345\33\0\0\0\0\0\0", 4096}], msg_controllen=0, msg_flags=0}, 0) = 20
close(6) = 0
socket(PF_INET, SOCK_DGRAM, IPPROTO_IP) = 6
connect(6, {sa_family=AF_INET, sin_port=htons(9999), sin_addr=inet_addr("127.0.0.1")}, 16) = 0
getsockname(6, {sa_family=AF_INET, sin_port=htons(45936), sin_addr=inet_addr("127.0.0.1")}, [16]) = 0
close(6) = 0
stat("/etc/localtime", {st_mode=S_IFREG|0644, st_size=2221, ...}) = 0
write(2, "2016-06-16 17:04:47: pid 7141: L"..., 74) = 74
socket(PF_INET, SOCK_STREAM, IPPROTO_TCP) = 6
setsockopt(6, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0
bind(6, {sa_family=AF_INET, sin_port=htons(9999), sin_addr=inet_addr("127.0.0.1")}, 16) = 0
listen(6, 64) = 0
stat("/etc/localtime", {st_mode=S_IFREG|0644, st_size=2221, ...}) = 0
write(2, "2016-06-16 17:04:47: pid 7141: L"..., 74) = 74
socket(PF_INET, SOCK_STREAM, IPPROTO_TCP) = 7
setsockopt(7, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0
bind(7, {sa_family=AF_INET, sin_port=htons(9999), sin_addr=inet_addr("127.0.0.1")}, 16) = -1 EADDRINUSE (Address already in use)
stat("/etc/localtime", {st_mode=S_IFREG|0644, st_size=2221, ...}) = 0
stat("/etc/localtime", {st_mode=S_IFREG|0644, st_size=2221, ...}) = 0
write(2, "2016-06-16 17:04:47: pid 7141: F"..., 173) = 173
rt_sigprocmask(SIG_SETMASK, ~[QUIT ILL TRAP ABRT BUS FPE SEGV ALRM TERM CONT SYS RTMIN RT_1], NULL, 8) = 0
--
semctl(950287, 0, IPC_RMID, 0x7f98eb3286da) = 0
shmdt(0x7f98ec5a4000) = 0
shmctl(16220170, IPC_STAT, 0x7ffd99dea4c0) = 0
shmctl(16220170, IPC_RMID, 0) = 0
unlink("/tmp/.s.PGSQL.9999") = 0
unlink("/var/run/pgpool/pgpool.pid") = 0
close(3) = 0
exit_group(3) = ?
+++ exited with 3 +++
TagsNo tags attached.

Activities

t-ishii

2016-06-17 18:21

developer   ~0000860

Did not reproduce here (Ubuntu 14.04 LTS, compiled from source code). Is there any specific hack in the package?

xlotlu

2016-06-18 08:58

reporter   ~0000861

I get this on 3.4.6 and 3.5.2 compiled from source as well, so it's not specific to the package. Must be something else debian-specific.

t-ishii

2016-06-18 17:35

developer   ~0000862

Probably getaddrinfo() call on your debian platform returns more than one entry for "localhost". According to PostgreSQL source code, it's possible (from src/backend/postmaster/pgstat.c):

    /*
     * On some platforms, pg_getaddrinfo_all() may return multiple addresses
     * only one of which will actually work (eg, both IPv6 and IPv4 addresses
     * when kernel will reject IPv6). Worse, the failure may occur at the
     * bind() or perhaps even connect() stage. So we must loop through the
     * results till we find a working combination. We will generate LOG
     * messages, but no error, for bogus combinations.
     */

xlotlu

2016-06-18 21:34

reporter   ~0000863

Turns out I had two "127.0.0.1 localhost" entries in my /etc/hosts.

I did a small test and indeed, getaddrinfo("localhost", ... ) returns two identical entries, although getaddrinfo(NULL, ... ) returns a single entry for the loopback interface.

So, besides user error this is debatably a bug in glibc.

t-ishii

2016-06-20 14:10

developer   ~0000864

Going to close this issue now.

Issue History

Date Modified Username Field Change
2016-06-16 23:22 xlotlu New Issue
2016-06-17 18:21 t-ishii Note Added: 0000860
2016-06-18 08:58 xlotlu Note Added: 0000861
2016-06-18 17:31 t-ishii Assigned To => t-ishii
2016-06-18 17:31 t-ishii Status new => assigned
2016-06-18 17:35 t-ishii Note Added: 0000862
2016-06-18 21:34 xlotlu Note Added: 0000863
2016-06-20 14:10 t-ishii Note Added: 0000864
2016-06-20 14:10 t-ishii Status assigned => resolved