Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hK3pp-0007Jk-TI for pgsql-general@arkaria.postgresql.org; Fri, 26 Apr 2019 16:36:26 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hK3pn-0004ER-DM for pgsql-general@arkaria.postgresql.org; Fri, 26 Apr 2019 16:36:23 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hK3pm-00047n-RL for pgsql-general@lists.postgresql.org; Fri, 26 Apr 2019 16:36:23 +0000 Received: from mail-lj1-x242.google.com ([2a00:1450:4864:20::242]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hK3pj-0004S0-Vw for pgsql-general@postgresql.org; Fri, 26 Apr 2019 16:36:22 +0000 Received: by mail-lj1-x242.google.com with SMTP id k8so3483636lja.8 for ; Fri, 26 Apr 2019 09:36:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=puris-lv.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:message-id:in-reply-to:references:subject :mime-version; bh=hV4NuL0H4PI6EHtzTp3P/h9OvWMrFiupvJXjakw9Uco=; b=bXNUVw4uhI6VXvfNnROSJwPlHEcJ9NpC359ZreefGi1qHrL3FnQlWl/YB12FEtgZUd eT80Gm4bw3hCzPuevB5oSqRauF8LUnFQdWOWXdihc61rlid4xr3p+BU3t645LETy6eU7 0cvdc55B/k5U4A7GdCmMB5jJ4WMBBFnITx9+5/KjApTnttejT6pLq9S5qBp0CQoa5Dh/ IMRnAQ8WcDhuvlsCQwQzppm/4ph11dc4rm/Idr3nkcQ+uVCwCh/n2fhIZnt8MR/9HIh2 XEkKpeIFmzotH9Fo4L33tZlA99o4xf6PuPFaWlOjY2VOzmoLUi/LToS252dMjeWk5ltW yttw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:message-id:in-reply-to :references:subject:mime-version; bh=hV4NuL0H4PI6EHtzTp3P/h9OvWMrFiupvJXjakw9Uco=; b=pZwGsCtwObfjF0LoyKElthzIkzmCMVU7cdHoSp0a6CiFfDgye/yfPHa58tfOBAcKhp 6X9/HlWh65gAkq6wf/ev/xgBiVOECHOgAL7llBVZjqPH6jGj+P/nH0eFV1GstqsZwwfc 11XV4COifG5Uk+ejSqh64xM/jxQQ21GGo9xkzDKlaIwn9Fko07Ll5tUfImE1Wl9B92jC rXTSe0E2Lr2058MaGc5D7cH+z8kajEcDUWbQeqkIrq6gIvTiLJs3pylmvUqN4hzIqHuO gSP2tF1BjhnWnMNhhOO7ccpfVTzTvlWNVoGdh2NSYPJVXN1LzCaRZfuQnhoQDs1N87YP ajbw== X-Gm-Message-State: APjAAAVUw7iinKwvn/DulQVBfVFWIyg/hAoCvlGMy+I+NJ3vCwQdcADM 85GS42v71lHMSvpI6no3W9xIXQ== X-Google-Smtp-Source: APXvYqwUFFlzcDiRl9mieJOkjuJz7Rdgn4p7ABt/Rw3eKhikY4Z4yqRY25SyKZT7/rSF70mwz/25cA== X-Received: by 2002:a2e:8446:: with SMTP id u6mr5766606ljh.71.1556296579076; Fri, 26 Apr 2019 09:36:19 -0700 (PDT) Received: from [172.25.29.22] (vpn.netwerk.no. [193.58.241.100]) by smtp.gmail.com with ESMTPSA id x3sm1682419ljd.38.2019.04.26.09.36.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 26 Apr 2019 09:36:18 -0700 (PDT) Date: Fri, 26 Apr 2019 18:36:12 +0200 From: =?utf-8?Q?J=C4=81nis_P=C5=ABris?= To: Tom Lane Cc: pgsql-general@postgresql.org Message-ID: <9718d4fc-de72-45bc-af1b-f759b9f2b29d@Spark> In-Reply-To: <31611.1556288224@sss.pgh.pa.us> References: <95b05f8d-990a-4f15-906f-24a011fc00ed@Spark> <695f797f-b02b-492a-94d3-0d5b4ab7c0a2@Spark> <31611.1556288224@sss.pgh.pa.us> Subject: Re: TCP Resets when closing connection opened via SSL X-Readdle-Message-ID: 9718d4fc-de72-45bc-af1b-f759b9f2b29d@Spark MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="5cc33381_1f48eaa1_331" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --5cc33381_1f48eaa1_331 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Thanks for the insight, Tom. > It's fairly obvious from the postmaster log that the client side > is not bothering to close the transaction it started Thats what I was also thinking, but I've managed to reproduce it with aut= ocommit or commit before closing connection as well. This is only=C2=A0reproducible with SSL connection. I've reproduced it with ubuntu package bundles certs, my own created, gen= erated with CA etc hence I do not think it is a problem with certificates= themselves. This happens with various clients, php driver, java driver and also libpq= used by psycopg2. We are running a lot of different kind of microservice= s and thus far I can tell, almost (if not all) of them have this problem = manifest. I can not however reproduce this when doing something like =24 psql =22user=3Dpostgres sslmode=3Drequire host=3Dlocalhost dbname=3Dp= ostgres=22 postgres=3D=23 =5Cq > So, please re-think why you are considering them problematic in the fir= st place. This is an issue because we have a lot of connections being initiated and= closed. And this creates a lot of TCP resets. We could go with something like pgbouncer in front of it to pool the conn= ections in order to reduce the reset count, but this would not be solving= the root cause, but merely working around it. Other than that, this does not seem to =22break=22 anything. This is basi= cally large noise for monitoring and huge numbers of resets, when looking= at something like netstat. And by no means, this happens casually. Has no one expieriencing this =3F Should I just assume this is =22normal=22 and forget about it =3F I'd sti= ll want to understand what's going on thought. Med vennlig hilsen. Best regards, Janis Puris. On 26 Apr 2019, 16:17 +0200, Tom Lane , wrote: > =3D=3Futf-8=3FQ=3FJ=3DC4=3D81nis=5FP=3DC5=3DABris=3F=3D writes: > > I'm trying to do a simple health check for keepalived and other servi= ces via a python script and=C2=A0psycopg2=C2=A0library. All seems to be a= ll right, until I close the connection, at which point a packet with TCP = reset is produced. > > Hm. It's fairly obvious from the postmaster log that the client side > is not bothering to close the transaction it started: > > > 2019-04-23 16:27:45.306 CEST process=3D15615 c=3DBEGIN t=3D0 s=3D5cbf= 20e1.3cff monitoring=40127.0.0.1:postgres app=3D=5Bunknown=5D LOG: durati= on: 0.095 ms > > 2019-04-23 16:27:45.306 CEST process=3D15615 c=3DSELECT t=3D0 s=3D5cb= f20e1.3cff monitoring=40127.0.0.1:postgres app=3D=5Bunknown=5D LOG: durat= ion: 0.234 ms > > 2019-04-23 16:27:45.306 CEST process=3D15615 c=3Didle in transaction = t=3D0 s=3D5cbf20e1.3cff monitoring=40127.0.0.1:postgres app=3D=5Bunknown=5D= LOG: disconnection: session time: 0:00:00.006 user=3Dmonitoring database= =3Dpostgres host=3D127.0.0.1 port=3D40797 > > There's no COMMIT or ROLLBACK to go with the BEGIN, and that's reflecte= d > in the fact that the disconnection message shows c=3Didle in transactio= n. > Now, I doubt that would have any impact on the TCP-level session behavi= or, > but it suggests that maybe the client isn't bothering to close the sess= ion > cleanly either. The RST rather than =46IN would then likely be caused b= y > SSL having to do an unclean shutdown. > > regards, tom lane --5cc33381_1f48eaa1_331 Content-Type: text/html; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline
Thanks for the insight, Tom.

It's fairly obvious = from the postmaster log that the client side
is not bothering to close the transaction it started

Thats what I was also thinking, but I've managed to reproduce it with aut= ocommit or commit before closing connection as well.
This is only&=23160;reproducible with SSL connection.

I've reproduced it with ubuntu package bundles certs, my own created= , generated with CA etc hence I do not think it is a problem with certifi= cates themselves.
This happens with various clients, php driver, java driver and also = libpq used by psycopg2. We are running a lot of different kind of microse= rvices and thus far I can tell, almost (if not all) of them have this pro= blem manifest.

I can not however rep= roduce this when doing something like
=24 psql =22user=3Dpo= stgres sslmode=3Drequire host=3Dlocalhost dbname=3Dpostgres=22
postgres=3D=23 =5Cq

So, please re-think w= hy you are considering them problematic in the first place.

This is an issue because we have a lot of= connections being initiated and closed. And this creates a lot of TCP re= sets.

We could go with some= thing like pgbouncer in front of it to pool the connections in order to r= educe the reset count, but this would not be solving the root cause, but = merely working around it.

Other than that, this= does not seem to =22break=22 anything. This is basically large noise for= monitoring and huge numbers of resets, when looking at something like ne= tstat. And by no means, this happens casually.

Has no one expierienc= ing this =3F
Should I just assume = this is =22normal=22 and forget about it =3F I'd still want to understand= what's going on thought.

Med vennlig hilsen.
Best regards, Janis Puris.
On 26 Apr 2019,= 16:17 +0200, Tom Lane <tgl=40sss.pgh.pa.us>, wrote:
=3D=3Futf-8=3FQ=3FJ=3DC4=3D81n= is=5FP=3DC5=3DABris=3F=3D <janis=40puris.lv> writes:
I'm trying to do a simple heal= th check for keepalived and other services via a python script and&=23160= ;psycopg2&=23160;library. All seems to be all right, until I close the co= nnection, at which point a packet with TCP reset is produced.

Hm. It's fairly obvious from the postmaster log that the client side
is not bothering to close the transaction it started:

2019-04-23 16:27:45.306 CEST p= rocess=3D15615 c=3DBEGIN t=3D0 s=3D5cbf20e1.3cff monitoring=40127.0.0.1:p= ostgres app=3D=5Bunknown=5D LOG: duration: 0.095 ms
2019-04-23 16:27:45.306 CEST process=3D15615 c=3DSELECT t=3D0 s=3D5cbf20e= 1.3cff monitoring=40127.0.0.1:postgres app=3D=5Bunknown=5D LOG: duration:= 0.234 ms
2019-04-23 16:27:45.306 CEST process=3D15615 c=3Didle in transaction t=3D= 0 s=3D5cbf20e1.3cff monitoring=40127.0.0.1:postgres app=3D=5Bunknown=5D L= OG: disconnection: session time: 0:00:00.006 user=3Dmonitoring database=3D= postgres host=3D127.0.0.1 port=3D40797

There's no COMMIT or ROLLBACK to go with the BEGIN, and that's reflected<= br /> in the fact that the disconnection message shows c=3Didle in transaction.=
Now, I doubt that would have any impact on the TCP-level session behavior= ,
but it suggests that maybe the client isn't bothering to close the sessio= n
cleanly either. The RST rather than =46IN would then likely be caused by<= br /> SSL having to do an unclean shutdown.

regards, tom lane
--5cc33381_1f48eaa1_331--