Re: [update] pgbouncer 1.8.1

2018-01-20 Thread Landry Breuil
On Sat, Jan 20, 2018 at 12:14:00PM +0100, Landry Breuil wrote:


> that explains why the 'compat' backend doesnt work. And that one is
> pretty hilarious :) The configure script has:
> 
> #include pthread.h
> 
> ... lol. 1.7.2 has it too :) And i have no idea where this interesting
> html comes from.. web 2.0 autoconf ?

Aaand after digging more, this gem comes from
https://github.com/libusual/libusual/blob/51d444927e55fed0523e03dd17b392fc70556023/m4/acx_pthread.m4#L117

> patching configure to fix that one yields:
> checking whether pthreads work with -pthread... yes
> 
> Aaaand this finally produces a working pgbouncer with hostnames, since i
> think it ends up falling back to our plain libc getaddrinfo. Maybe. I
> don't really know, 
> https://github.com/pgbouncer/pgbouncer/blob/master/src/dnslookup.c
> is a maze :)

In the end we use the getaddrinfo_a compat function from here:
https://github.com/libusual/libusual/blob/51d444927e55fed0523e03dd17b392fc70556023/usual/netdb.c#L179

Landry



Re: [update] pgbouncer 1.8.1

2018-01-20 Thread Landry Breuil
On Fri, Jan 19, 2018 at 03:48:52PM +0100, Landry Breuil wrote:
> Hi,
> 
> had to backport pgbouncer 1.7 to 6.2 ( i need auth_type = hba) and then
> i realized upstream released 1.8 and 1.8.1 (which i'm already running on
> debian), see https://pgbouncer.github.io/changelog.html#pgbouncer-18x
> 
> easy diff, only build-tested :)

While trying to do some actual realworld testing, found something
'strange'.

with a simple remote database definition such as:

gis = host=localhost db=gis

pgbouncer as is fails to resolve localhost (and it uses dns a lot, cf
https://github.com/pgbouncer/pgbouncer#dns-lookup-support) and
connecting to it timeouts when it tries to reach the remote db.

and in the log i get:
WARNING dns: getaddrinfo_a(localhost)=-11, errno=78 (Function not implemented)
LOG S-0x14c2e5dd9010: gis/gis@(bad-af):0 closing because: server dns lookup 
failed (age=0)

seems it tries to use the glibc-only getaddrinfo_a function. It uses the
'compat' adns backend:

process up: pgbouncer 1.8.1, libevent 1.4.15-stable (kqueue), adns: compat, 
tls: LibreSSL 2.7.0

of course i get no issue connecting directly:

$psql -h localhost -d gis -U gis
Password for user gis:
psql (10.1)

$psql -h localhost -p 6432 -d gis -U gis
Password for user gis:


This is not a regression, i get the same thing with 1.7.2. It of course
works fine if i use an ip in the database definition.

I've briefly tested --enable-evdns to keep changes to a minimal since we
already link with libevent1, but then linking fails:

src/dnslookup.c:(.text+0x7f): undefined reference to `evdns_init'
src/dnslookup.c:(.text+0x8a): undefined reference to `evdns_shutdown'
src/dnslookup.c:(.text+0x252): undefined reference to `evdns_shutdown'
src/dnslookup.c:(.text+0x3ad): undefined reference to `evdns_resolve_ipv4'

It 'builds' if i add LDFLAGS='-L${LOCALBASE}/lib -leventextra -levent'
to CONFIGURE_ENV (and libeventextra should move to a LDEP) but that
doesnt *work* at runtime:

LOG process up: pgbouncer 1.8.1, libevent 1.4.15-stable (kqueue), adns:evdns1, 
tls: LibreSSL 2.7.0
...
WARNING lookup failed: localhost: result=1
LOG S-0x33370334010: gis2/gis@(bad-af):0 closing because: server dns lookup 
failed (age=0)

And anyway, upstream seem to say that evdns/libevent1 dns backend is
buggy. Havent digged more in this direction, since our libevent
situation is.. particular.

Looking at the configure output, i then noticed this:
checking for pthread-config... no
Threads not available and fallback getaddrinfo_a() non-functional.

that explains why the 'compat' backend doesnt work. And that one is
pretty hilarious :) The configure script has:

#include pthread.h

... lol. 1.7.2 has it too :) And i have no idea where this interesting
html comes from.. web 2.0 autoconf ?

patching configure to fix that one yields:
checking whether pthreads work with -pthread... yes

Aaaand this finally produces a working pgbouncer with hostnames, since i
think it ends up falling back to our plain libc getaddrinfo. Maybe. I
don't really know, 
https://github.com/pgbouncer/pgbouncer/blob/master/src/dnslookup.c
is a maze :)

so, time to move to libevent2 ? use c-ares ? just patch configure to fix
pthread detection, like the attached patch does ?

Of course i can commit the upgrade as-is now (got an okay from
maintainer, thanks :) since that's not a regression, and can fix the dns
thing separately..

So, thoughts ? That was a quite puzzling one...

Landry
Index: Makefile
===
RCS file: /cvs/ports/databases/pgbouncer/Makefile,v
retrieving revision 1.25
diff -u -r1.25 Makefile
--- Makefile11 Jan 2018 19:27:01 -  1.25
+++ Makefile20 Jan 2018 11:10:18 -
@@ -2,9 +2,8 @@
 
 COMMENT =  lightweight connection pooler for PostgreSQL
 
-V =1.7.2
+V =1.8.1
 DISTNAME = pgbouncer-${V}
-REVISION =  0
 
 CATEGORIES =   databases
 
Index: distinfo
===
RCS file: /cvs/ports/databases/pgbouncer/distinfo,v
retrieving revision 1.10
diff -u -r1.10 distinfo
--- distinfo19 Dec 2017 08:58:15 -  1.10
+++ distinfo20 Jan 2018 11:10:18 -
@@ -1,2 +1,2 @@
-SHA256 (pgbouncer-1.7.2.tar.gz) = 3jazGP5KLyCl9g0cXqYsHKMx9oE9LEhIZuy1kmWhYLo=
-SIZE (pgbouncer-1.7.2.tar.gz) = 462374
+SHA256 (pgbouncer-1.8.1.tar.gz) = +oveKi0sjIDVOoWfjki8ZxPPEn4xx32PeHu8HWc+jcg=
+SIZE (pgbouncer-1.8.1.tar.gz) = 465930
Index: patches/patch-configure
===
RCS file: patches/patch-configure
diff -N patches/patch-configure
--- /dev/null   1 Jan 1970 00:00:00 -
+++ patches/patch-configure 20 Jan 2018 11:10:18 -
@@ -0,0 +1,14 @@
+$OpenBSD$
+
+Index: configure
+--- configure.orig
 configure
+@@ -7190,7 +7190,7 @@ $as_echo_n "checking for the pthreads library -l$flag.
+ # We try pthread_create on general principles.
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext

[update] pgbouncer 1.8.1

2018-01-19 Thread Landry Breuil
Hi,

had to backport pgbouncer 1.7 to 6.2 ( i need auth_type = hba) and then
i realized upstream released 1.8 and 1.8.1 (which i'm already running on
debian), see https://pgbouncer.github.io/changelog.html#pgbouncer-18x

easy diff, only build-tested :)

Landry
Index: Makefile
===
RCS file: /cvs/ports/databases/pgbouncer/Makefile,v
retrieving revision 1.25
diff -u -r1.25 Makefile
--- Makefile11 Jan 2018 19:27:01 -  1.25
+++ Makefile19 Jan 2018 14:36:21 -
@@ -2,9 +2,8 @@
 
 COMMENT =  lightweight connection pooler for PostgreSQL
 
-V =1.7.2
+V =1.8.1
 DISTNAME = pgbouncer-${V}
-REVISION =  0
 
 CATEGORIES =   databases
 
Index: distinfo
===
RCS file: /cvs/ports/databases/pgbouncer/distinfo,v
retrieving revision 1.10
diff -u -r1.10 distinfo
--- distinfo19 Dec 2017 08:58:15 -  1.10
+++ distinfo19 Jan 2018 14:36:21 -
@@ -1,2 +1,2 @@
-SHA256 (pgbouncer-1.7.2.tar.gz) = 3jazGP5KLyCl9g0cXqYsHKMx9oE9LEhIZuy1kmWhYLo=
-SIZE (pgbouncer-1.7.2.tar.gz) = 462374
+SHA256 (pgbouncer-1.8.1.tar.gz) = +oveKi0sjIDVOoWfjki8ZxPPEn4xx32PeHu8HWc+jcg=
+SIZE (pgbouncer-1.8.1.tar.gz) = 465930
Index: patches/patch-etc_pgbouncer_ini
===
RCS file: /cvs/ports/databases/pgbouncer/patches/patch-etc_pgbouncer_ini,v
retrieving revision 1.4
diff -u -r1.4 patch-etc_pgbouncer_ini
--- patches/patch-etc_pgbouncer_ini 19 Dec 2017 13:44:35 -  1.4
+++ patches/patch-etc_pgbouncer_ini 19 Jan 2018 14:36:21 -
@@ -2,16 +2,16 @@
 Index: etc/pgbouncer.ini
 --- etc/pgbouncer.ini.orig
 +++ etc/pgbouncer.ini
-@@ -98,7 +98,7 @@ listen_port = 6432
+@@ -103,7 +103,7 @@ listen_port = 6432
  ;;;
  
- ; any, trust, plain, crypt, md5
+ ; any, trust, plain, crypt, md5, cert, hba, pam
 -auth_type = trust
 +auth_type = md5
  ;auth_file = /8.0/main/global/pg_auth
  auth_file = /etc/pgbouncer/userlist.txt
  
-@@ -114,7 +114,7 @@ auth_file = /etc/pgbouncer/userlist.txt
+@@ -119,7 +119,7 @@ auth_file = /etc/pgbouncer/userlist.txt
  ;;;
  
  ; comma-separated list of users, who are allowed to change settings
Index: patches/patch-lib_usual_tls_tls_c
===
RCS file: /cvs/ports/databases/pgbouncer/patches/patch-lib_usual_tls_tls_c,v
retrieving revision 1.1
diff -u -r1.1 patch-lib_usual_tls_tls_c
--- patches/patch-lib_usual_tls_tls_c   19 Dec 2017 08:58:15 -  1.1
+++ patches/patch-lib_usual_tls_tls_c   19 Jan 2018 14:36:21 -
@@ -3,7 +3,7 @@
 Index: lib/usual/tls/tls.c
 --- lib/usual/tls/tls.c.orig
 +++ lib/usual/tls/tls.c
-@@ -287,7 +287,7 @@ tls_info_callback(const SSL *ssl, int where, int rc)
+@@ -350,7 +350,7 @@ tls_info_callback(const SSL *ssl, int where, int rc)
  {
struct tls *ctx = SSL_get_app_data(ssl);