Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kShwX-00026i-BW for psycopg@arkaria.postgresql.org; Wed, 14 Oct 2020 14:39:53 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kShwW-0002T2-7i for psycopg@arkaria.postgresql.org; Wed, 14 Oct 2020 14:39:52 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kShdf-0000U8-If for psycopg@lists.postgresql.org; Wed, 14 Oct 2020 14:20:23 +0000 Received: from mail-io1-xd2c.google.com ([2607:f8b0:4864:20::d2c]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kShdb-0000Gn-Kp for psycopg@postgresql.org; Wed, 14 Oct 2020 14:20:22 +0000 Received: by mail-io1-xd2c.google.com with SMTP id r4so5350986ioh.0 for ; Wed, 14 Oct 2020 07:20:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=fDj3VHdJacrHzMUg5TkponIua9L0U/+4gcIKTAxS3HA=; b=TRx3Ud/Ndli4iPoBO2Hwkrn9yBgB/5Schi+MocUasM7SsfN+ZK/CnhCjGNPl20xrLN im7HhfdOlf6wIGL67/xXgZrR0QkPcgZxjaNrExiOmHSQPB8xKlE0Gma9q9xGThIvIpBg e1dDrzih7avYJgzYIx9le4a9BKZTAAnsNwt3j394ODyq8LqMCf/tUviYyjDKDYLU6xhJ UKnC582xAgh1OaVep/mUiPCfaCvD4z0EuiqSLIr54A9VIHM7UHOEHwn5/70kp8j9LQcy eNqoX/OUyfuW9yBfKUb5igOuQNQCbv5llxgfFE30XsSHL62yMtUisNqTSsPj+d2oQ4G4 uJpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=fDj3VHdJacrHzMUg5TkponIua9L0U/+4gcIKTAxS3HA=; b=HePksiTNIP21uzBbr0DIqLWujeH0TQa3snDw5E6fZfyRV8PRGsInNyfD6tDUoauZq0 4RZcpVsiY0XogYZxrJLO+VviZXWVJcxeNlmtozdSGnB+3nriqscrCpLiJhgD00W5Mgvz fs5r8u6Sya92sbjDsxn6il8IWr3KY6QFnXKQVqq4R8MOOBJMhGfwybo9li7nxVHsXFrY WAibcPQCZgQkPmQdt3a00sq2E+/AHMtTovu8XTorVQ7Ohqrwp+uuAyTe913ggEoMLbFt L+x4eB3etsbSytH6ZlDvHonlg4WGxYAsKZ8C0FtDQyqf3j9VXtjGYam2WMX0+4cgrHPE mMVg== X-Gm-Message-State: AOAM531GRh4e7k4Dp/U9P1AP8LkwkkEPfMyOl44KqLVq1reMvg0SoGzo VOS8BOFy40+2V3IFOF/3wuwt8X4lwIUCFRXqZyVs25RqNkxefjnO X-Google-Smtp-Source: ABdhPJyJu75GpG3TUnUhMGjeKG+VuYuGSLrD4U5insMIJRBbJW0fACSZEL18RdtbKK+g0y51X6kD/7bQa1/ZnDjiGHc= X-Received: by 2002:a6b:144e:: with SMTP id 75mr3019064iou.39.1602685216904; Wed, 14 Oct 2020 07:20:16 -0700 (PDT) MIME-Version: 1.0 From: Mark Charsley Date: Wed, 14 Oct 2020 15:20:05 +0100 Message-ID: Subject: Possible data race in psycopg2 To: psycopg@postgresql.org Content-Type: multipart/alternative; boundary="0000000000000adb1a05b1a23b7a" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --0000000000000adb1a05b1a23b7a Content-Type: text/plain; charset="UTF-8" Hi. I've started a little project that uses psycopg2, and hit a problem when running tests under ThreadSanitizer: WARNING: ThreadSanitizer: data race (pid=9435) Read of size 4 at 0x7b44000aae38 by thread T7: #0 psyco_conn_cursor psycopg2/psycopg/connection_type.c:88:15 (_ psycopg.abi3.so+0x2a434) Previous write of size 4 at 0x7b44000aae38 by thread T6 (mutexes: write M142280395227573736): #0 pq_begin_locked psycopg2/psycopg/pqpath.c:377:22 (_psycopg.abi3.so +0x38766) #1 _pq_execute_sync psycopg2/psycopg/pqpath.c:819:22 (_psycopg.abi3.so +0x3923e) #2 pq_execute psycopg2/psycopg/pqpath.c:947:16 (_psycopg.abi3.so +0x3abd7) #3 _psyco_curs_execute psycopg2/psycopg/cursor_type.c:447:11 (_ psycopg.abi3.so+0x32820) #4 curs_execute psycopg2/psycopg/cursor_type.c:491:13 (_psycopg.abi3.so +0x2f92b) It's possible that this is caused by an underlying failure in the postgres server, where thread sanitizer panics about a safe-except-under-the-most-insanely-optimising-compiler issue, discussed here: https://www.postgresql.org/message-id/CAAf4L0d5XpgmX%2BnzT2G_F7EPkJb2JODr_QCzOsSvWBnXxLKYVQ%40mail.gmail.com which may have killed the server (the tests I'm running compile everything, including the DB server with tsan), and handling the dead connection causes the issues mentioned above. But can wiser and more experienced heads than mine cast their eyes over the code above, and see if there is indeed a problem with a write to conn_status in pq_begin_lockedand a read from it in psyco_conn_cursor without a memory barrier in-between? thanks Mark --0000000000000adb1a05b1a23b7a Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi. I've started a little project that uses psycopg2, = and hit a problem when running tests under ThreadSanitizer:

<= div>WARNING: ThreadSanitizer: data race (pid=3D9435)
=C2=A0 Read of size= 4 at 0x7b44000aae38 by thread T7:
=C2=A0 =C2=A0 #0 psyco_conn_cursor ps= ycopg2/psycopg/connection_type.c:88:15 (_psycopg.abi3.so+0x2a434)

=C2=A0 Previous write of size 4 at 0x7= b44000aae38 by thread T6 (mutexes: write M142280395227573736):
=C2=A0 = =C2=A0 #0 pq_begin_locked psycopg2/psycopg/pqpath.c:377:22 (_psycopg.abi3.so+0x38766)
=C2=A0 =C2=A0 #1 _pq_e= xecute_sync psycopg2/psycopg/pqpath.c:819:22 (_psycopg.abi3.so+0x3923e)
=C2=A0 =C2=A0 #2 pq_execute psycopg2= /psycopg/pqpath.c:947:16 (_psycopg.abi3.= so+0x3abd7)
=C2=A0 =C2=A0 #3 _psyco_curs_execute psycopg2/psycopg/cu= rsor_type.c:447:11 (_psycopg.abi3.so= +0x32820)
=C2=A0 =C2=A0 #4 curs_execute psycopg2/psycopg/cursor_type.c:4= 91:13 (_psycopg.abi3.so+0x2f92b)
=
It's possible that this is caused by an underlying failu= re in the postgres server, where thread sanitizer panics about a safe-excep= t-under-the-most-insanely-optimising-compiler issue, discussed here:=C2=A0<= a href=3D"https://www.postgresql.org/message-id/CAAf4L0d5XpgmX%2BnzT2G_F7EP= kJb2JODr_QCzOsSvWBnXxLKYVQ%40mail.gmail.com">https://www.postgresql.org/mes= sage-id/CAAf4L0d5XpgmX%2BnzT2G_F7EPkJb2JODr_QCzOsSvWBnXxLKYVQ%40mail.gmail.= com which may have killed the server (the tests I'm running compile= everything, including the DB server with tsan), and handling the dead conn= ection causes the issues mentioned above. But can wiser and more experience= d heads than mine cast their eyes over the code above, and see if there is = indeed a problem with a write to conn_status in=C2=A0pq_begin_= lockedand a read from it in=C2=A0psyco_conn_cursor=C2=A0without a memory barrier in-between?

thank= s

Mark
--0000000000000adb1a05b1a23b7a--