public inbox for [email protected]  
help / color / mirror / Atom feed
From: Mark Charsley <[email protected]>
To: [email protected]
Subject: Possible data race in psycopg2
Date: Wed, 14 Oct 2020 15:20:05 +0100
Message-ID: <CAAf4L0eqm6hozAZyKP005a6UEPnnQcQe-=qznbnOr6B-tQSCAw@mail.gmail.com> (raw)

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.g...
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


reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected]
  Subject: Re: Possible data race in psycopg2
  In-Reply-To: <CAAf4L0eqm6hozAZyKP005a6UEPnnQcQe-=qznbnOr6B-tQSCAw@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox