agora inbox for pgsql-docs@postgresql.org
help / color / mirror / Atom feedFrom: PG Doc comments form <noreply@postgresql.org>
To: pgsql-docs@lists.postgresql.org
Cc: victorrachels@gmail.com
Subject: Threading issue / maybe just doc issue.
Date: Mon, 17 Feb 2025 21:38:32 +0000
Message-ID: <173982831219.682633.14981749272293948621@wrigleys.postgresql.org> (raw)
The following documentation comment has been logged on the website:
Page: https://www.postgresql.org/docs/17/libpq-threading.html
Description:
commit
https://github.com/postgres/postgres/commit/515112f9d4874aaedd0c093f41c0ba3e0bf7f660
added global variables for backward compatibility support:
static_client_encoding, static_std_strings
If multiple threads are creating connections at the same time, this can
result in a data race in pqSaveParameterStatus where both attempts to
connect try to set those global variables.
If those are the same value for all users of the library, this might be
okay. This is mentioned in the commit comment:
> This will work reliably in clients using only one Postgres
connection at a time, or even multiple connections if they all use the
same
encoding and string syntax settings; which should cover many practical
scenarios.
But it does not cover the other use cases, where all uses in the program do
not have the same settings.
Additionally, this implementation causes thread sanitizer tests to fail,
even in the 'safe' use case. A data race occurs and is flagged as an error
when multiple threads connect at the same time and attempt to update the
global variable.
The documentation at
https://www.postgresql.org/docs/current/libpq-threading.html does not
reference this issue at all, and in fact suggests to create multiple
connections.
There is no clear workaround within the library for the 'safe' method other
than locking the connection generators, or marking this tsan error as
acceptable. There does not seem to be a workaround at all for the
'unsupported' case.
At the very least, I would suggest update the threading documentation with
this usage caveat.
Message-ID: <173982831219.682633.14981749272293948621@wrigleys.postgresql.org>
Permalink: ../173982831219.682633.14981749272293948621@wrigleys.postgresql.org/
Also on: postgresql.org/message-id/173982831219.682633.14981749272293948621@wrigleys.postgresql.org
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: pgsql-docs@postgresql.org
Cc: noreply@postgresql.org, pgsql-docs@lists.postgresql.org, victorrachels@gmail.com
Subject: Re: Threading issue / maybe just doc issue.
In-Reply-To: <173982831219.682633.14981749272293948621@wrigleys.postgresql.org>
* 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