Threading issue / maybe just doc issue.

From: PG Doc comments form <noreply(at)postgresql(dot)org>
To: pgsql-docs(at)lists(dot)postgresql(dot)org
Cc: victorrachels(at)gmail(dot)com
Subject: Threading issue / maybe just doc issue.
Date: 2025-02-17 21:38:32
Message-ID: 173982831219.682633.14981749272293948621@wrigleys.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-docs

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.

Browse pgsql-docs by date

  From Date Subject
Next Message David G. Johnston 2025-02-17 21:54:24 Re: Text correction
Previous Message PG Doc comments form 2025-02-17 05:01:48 pg_copy_logical_replication_slot doesn't copy the failover property