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 1hJvNr-0001iN-H7 for pgsql-general@arkaria.postgresql.org; Fri, 26 Apr 2019 07:35:00 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hJvNq-00053x-1X for pgsql-general@arkaria.postgresql.org; Fri, 26 Apr 2019 07:34:58 +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 1hJvNp-00053q-Ek for pgsql-general@lists.postgresql.org; Fri, 26 Apr 2019 07:34:57 +0000 Received: from mail-lf1-x134.google.com ([2a00:1450:4864:20::134]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hJvNi-0008Fa-CB for pgsql-general@postgresql.org; Fri, 26 Apr 2019 07:34:57 +0000 Received: by mail-lf1-x134.google.com with SMTP id v1so1731034lfg.5 for ; Fri, 26 Apr 2019 00:34:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=puris-lv.20150623.gappssmtp.com; s=20150623; h=date:from:to:message-id:in-reply-to:references:subject:mime-version; bh=NUs9TlJ2GVwF9T8hUKi+1pax0NX0R588pHh96+P4WI8=; b=MUO49q0PPVTfyTABDYI7M6p2k6wkHC45BOODJu++tvyCS52G8z18NNd7odrOIJpdYK bW3iUnwn5aKYrZ0h3hjpfFmzI8O6MSwWs93RmPPnauYSC2+p37t0lFklWS8+E7jZa1Mh 0OBQAitb7EeNKdLewHyMVlN1XhG8vkVoxhMc1NL99mqUxQqBlei9F5YOFnY0aW/DZbyw epYwWI5il2CxTTFv3FzML1txbBLiKyVfgbIZqmTNfyYCRnQ4gTWiCT0aAc87yyTsz5QQ Y+AJQ49f5ZTf7ppuBNW3gzkXwJtXveIXJLTNAiZ5l53j7GwNVNEydNLBCkrK2b8Sf3wo 8nzA== 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:message-id:in-reply-to:references :subject:mime-version; bh=NUs9TlJ2GVwF9T8hUKi+1pax0NX0R588pHh96+P4WI8=; b=aERDwx9zRsgoh4uFn46Ly8fIYqDeyI9qIlM7pXtkg4Pc2XoBN7/NRHa8YUADrpCXzZ 7sNOjvOrXKr6sp1mraNmgeCLv43SdM1k/XSFu6kthJBT2q6IAGlYM85w+Kfgw5IWH+Ba /a2TSfTMsqYacLz0Hp9vtV9UiMpmeKzp5WNFp1uAZwiQ6RO/VHjrl2iCEDufBG8S+Kvu 1cOUIhzrzQd3fdbxEEaAaqfGr+KvzaUN4ME4JKsVS/2zABL3UBrhvSGmgHJ4AJ9aphmP IBp2W0vOPV6SkKL8LvBXILVf7cWWO3S3DopDht+s/+3tsyI4NHQwnuHJG8slyA99uA9R NNJA== X-Gm-Message-State: APjAAAVmjG3kLzL0pbp32U5O9FyHXSv/AHlY9llUooNS76Mg+tyqpqgI j1sbcqNffOeQKXTzrQMaYqSCvZw8O/Xxdg== X-Google-Smtp-Source: APXvYqzqjQoBIAlVn/DhCktVRF4NVigV3GPCEquF37Z5SSvaBAX26cdT/Bc0I/7WBmz2OiIIwJ0J5Q== X-Received: by 2002:ac2:523a:: with SMTP id i26mr18945205lfl.118.1556264088119; Fri, 26 Apr 2019 00:34:48 -0700 (PDT) Received: from [172.25.29.21] (vpn.netwerk.no. [193.58.241.100]) by smtp.gmail.com with ESMTPSA id h14sm4967458ljg.10.2019.04.26.00.34.47 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 26 Apr 2019 00:34:47 -0700 (PDT) Date: Fri, 26 Apr 2019 09:34:38 +0200 From: =?utf-8?Q?J=C4=81nis_P=C5=ABris?= To: pgsql-general@postgresql.org Message-ID: <695f797f-b02b-492a-94d3-0d5b4ab7c0a2@Spark> In-Reply-To: <95b05f8d-990a-4f15-906f-24a011fc00ed@Spark> References: <95b05f8d-990a-4f15-906f-24a011fc00ed@Spark> Subject: TCP Resets when closing connection opened via SSL X-Readdle-Message-ID: 695f797f-b02b-492a-94d3-0d5b4ab7c0a2@Spark MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="5cc2b496_8edbdab_331" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --5cc2b496_8edbdab_331 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Hello, I'm trying to do a simple health check for keepalived and other services = via a python script and=C2=A0psycopg2=C2=A0library. All seems to be all r= ight, until I close the connection, at which point a packet with TCP rese= t is produced. This has become very problematic and creates extensive noise in monitorin= g. It also happens with IntelliJ DataGrip provided Java driver and PHP drive= rs. And hence I do not think this is the drivers problem, but PG instead.= Script import psycopg2 import sys def check(): =23 Relying on .pgpass for password con =3D psycopg2.connect('user=3Dmonitoring dbname=3Dpostgres host=3D1= 27.0.0.1') cur =3D con.cursor() cur.execute(=22select 'keepalived healthcheck'=22) cur.close() con.close() try: check() print(=22ok=22) except Exception as e: print(=22not ok=22) print(str(e)) sys.exit(1) tcpdump=C2=A0tcpdump -v 'tcp=5Btcpflags=5D & (tcp-rst) =21=3D 0' -ilo 16:27:45.307006 IP (tos 0x0, ttl 64, id 8123, offset 0, flags =5BD=46=5D,= proto TCP (6), length 40) localhost.40797 > localhost.postgres: =46lags =5BR=5D, cksum 0x0cca (c= orrect), seq 3830516781, win 0, length 0 =46rom PG side of things, all seems to be OK 2019-04-23 16:27:45.300 CEST process=3D15615 c=3D t=3D0 s=3D5cbf20e1.3cff= =5Bunknown=5D=40127.0.0.1:=5Bunknown=5D app=3D=5Bunknown=5D LOG: connec= tion received: host=3D127.0.0.1 port=3D40797 2019-04-23 16:27:45.304 CEST process=3D15615 c=3Dauthentication t=3D0 s=3D= 5cbf20e1.3cff monitoring=40127.0.0.1:postgres app=3D=5Bunknown=5D LOG: c= onnection authorized: user=3Dmonitoring database=3Dpostgres SSL enabled (= protocol=3DTLSv1.2, cipher=3DECDHE-RSA-AES256-GCM-SHA384, compression=3Do= ff) 2019-04-23 16:27:45.306 CEST process=3D15615 c=3DBEGIN t=3D0 s=3D5cbf20e1= .3cff monitoring=40127.0.0.1:postgres 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 I've tried various combinations of OS, psycopg2 and PG versions to no ava= il. My focus has been to reproduce with this driver only. =E2=80=A2 OS: Centos 7 and Ubuntu 18.04 =E2=80=A2 psycopg2: =46rom latest down to 2.7.x =E2=80=A2 PG: Latest 11 down to 9.4 (we use 9.4-bdr currently in producti= on) I can not reproduce this, when SSL has been disabled on PG. However this = is not a solution, as we are committed to use SSL for all our connections= to DB. Has anyone experienced this and could share any advice how I could preven= t this from producing network packets with TCP =5BR=5D flag =3F Thank you very much in advance and any advice will be much appreciated. P.S. I've also posted this on following channels: =E2=80=A2 https://dba.stackexchange.com/questions/235497/tcp-resets-when-= using-psycopg2 =E2=80=A2 https://github.com/psycopg/psycopg2/issues/906 Med vennlig hilsen. Best regards, Janis Puris. --5cc2b496_8edbdab_331 Content-Type: text/html; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline

Hello,


I'm trying to do a simple health check for keep= alived and other services via a python script and&=23160;psycopg2&=23160;library. All seems to be all right, until I close the connectio= n, at which point a packet with TCP reset is produced.

This has become very problematic and creates ex= tensive noise in monitoring.

It also happens with IntelliJ DataGrip provided= Java driver and PHP drivers. And hence I do not think this is the driver= s problem, but PG instead.


Script=

import psycopg2
import sys


def check<=
span class=3D=22pun=22 style=3D=22margin: 0px; padding: 0px; border: 0px;=
 font-family: inherit; font-style: inherit; font-variant-caps: inherit; f=
ont-stretch: inherit; line-height: inherit; vertical-align: baseline; box=
-sizing: inherit; color: rgb(196, 194, 189);=22>():
    =23 Relying on .pgpass for password
    con =3D psycopg2.connect('u=
ser=3Dmonitoring dbname=3Dpostgres host=3D127.0.0.1')
    cur =3D con.cursor()
    cur.execute(=22select 'keepalived healthcheck'=22)
    cur.close()
    con.close()

try:
    check<=
span class=3D=22pun=22 style=3D=22margin: 0px; padding: 0px; border: 0px;=
 font-family: inherit; font-style: inherit; font-variant-caps: inherit; f=
ont-stretch: inherit; line-height: inherit; vertical-align: baseline; box=
-sizing: inherit; color: rgb(196, 194, 189);=22>()
    print<=
span class=3D=22pun=22 style=3D=22margin: 0px; padding: 0px; border: 0px;=
 font-family: inherit; font-style: inherit; font-variant-caps: inherit; f=
ont-stretch: inherit; line-height: inherit; vertical-align: baseline; box=
-sizing: inherit; color: rgb(196, 194, 189);=22>(=22ok=22)
except Exception as e:
    print<=
span class=3D=22pun=22 style=3D=22margin: 0px; padding: 0px; border: 0px;=
 font-family: inherit; font-style: inherit; font-variant-caps: inherit; f=
ont-stretch: inherit; line-height: inherit; vertical-align: baseline; box=
-sizing: inherit; color: rgb(196, 194, 189);=22>(=22not ok=22)
    print<=
span class=3D=22pun=22 style=3D=22margin: 0px; padding: 0px; border: 0px;=
 font-family: inherit; font-style: inherit; font-variant-caps: inherit; f=
ont-stretch: inherit; line-height: inherit; vertical-align: baseline; box=
-sizing: inherit; color: rgb(196, 194, 189);=22>(str(e))
    sys.exit(1)<=
/span>

tcpdump&=23160;tcpdump -v 'tcp=5Btcpflags=5D & (= tcp-rst) =21=3D 0' -ilo

16:27:45.307006 IP (tos 0x0, ttl 64, id 8123, offset 0,<=
/span> flags =5BD=46=5D, proto TCP (<=
/span>6), length 40)=

    localhost.407=
97 > localhost.postgres: =46lags =5BR=5D, cksum 0x0cca (correct), seq 3830516781, win 0, length =
0

=46rom PG side of things, all seems to be OK=

2019-04-23 16:27:45.300 =
CEST process=3D15615 c=3D t=3D=
0 s=3D5cbf20=
e1.3cff =5Bunknown=5D=40127.0.0=
.1:=5Bunknown=5D app=3D=5Bunk=
nown=5D LOG:  connection received: host=3D<=
span class=3D=22lit=22 style=3D=22margin: 0px; padding: 0px; border: 0px;=
 font-family: inherit; font-style: inherit; font-variant-caps: inherit; f=
ont-stretch: inherit; line-height: inherit; vertical-align: baseline; box=
-sizing: inherit; color: rgb(204, 148, 148);=22>127.0.0.1 port=3D40797=

2019-04-23=
 16:27:45.304 CEST process=3D15615=
 c=3Dauthentication t=3D0 s=3D=
5cbf20e1.3cff monitoring=40127=
.0.0.1:postgres app=3D=5Bunknown=5D LOG:  connection authorized=
: user=3Dmon=
itoring database<=
/span>=3Dpostgres SSL enabled (protocol=3DTLSv1.2, cipher=3DECDHE-RSA-AES256-GCM-SHA384, compression=
=3Doff)
2019-04-23=
 16:27:45.306 CEST process=3D15615=
 c=3DBEGIN t=3D0 s=3D5cbf20e1.3cff monitoring=
=40127.0.0.1:postgres app=3D=5Bun=
known=5D LOG:  duration: <=
span class=3D=22lit=22 style=3D=22margin: 0px; padding: 0px; border: 0px;=
 font-family: inherit; font-style: inherit; font-variant-caps: inherit; f=
ont-stretch: inherit; line-height: inherit; vertical-align: baseline; box=
-sizing: inherit; color: rgb(204, 148, 148);=22>0.095 ms
2019-04-23=
 16:27:45.306 CEST process=3D15615=
 c=3DSELECT t=3D0 s=3D5cbf20e1.3cff monitoring=
=40127.0.0.1:postgres app=3D=5Bun=
known=5D LOG:  duration: <=
span class=3D=22lit=22 style=3D=22margin: 0px; padding: 0px; border: 0px;=
 font-family: inherit; font-style: inherit; font-variant-caps: inherit; f=
ont-stretch: inherit; line-height: inherit; vertical-align: baseline; box=
-sizing: inherit; color: rgb(204, 148, 148);=22>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:  disconnect=
ion: session time: 0:<=
span class=3D=22lit=22 style=3D=22margin: 0px; padding: 0px; border: 0px;=
 font-family: inherit; font-style: inherit; font-variant-caps: inherit; f=
ont-stretch: inherit; line-height: inherit; vertical-align: baseline; box=
-sizing: inherit; color: rgb(204, 148, 148);=22>00:00.006 user=3Dmonitoring database=3D=
postgres host=3D<=
/span>127.0.0.1 port=3D40797

I've tried various combinations of OS, psyco= pg2 and PG versions to no avail. My focus ha= s been to reproduce with this driver only.

  • OS: Centos 7 and Ubuntu 18.04
  • =
  • psycopg2: =46rom latest down to 2.7.x&=23= 160;
  • PG: Latest 11 down to 9.4 (we use 9.4-bdr currently= in production)
I can not reproduce this, when SSL has been disabled on PG. However this is not a solution, as we are committed to use SSL for all = our connections to DB.

Has anyone experienced this and could share = any advice how I could prevent this from producing network packets with T= CP =5BR=5D flag =3F


Thank you very much in advance and any ad= vice will be much appreciated.


P.S. I've also posted this on following chan= nels:


Med vennlig hilsen.
Best regards, Janis Puris.
--5cc2b496_8edbdab_331--