Re: Data race in interfaces/libpq/fe-exec.c

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Mark Charsley <mcharsley(at)google(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Data race in interfaces/libpq/fe-exec.c
Date: 2020-01-30 16:46:24
Message-ID: 22989.1580402784@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Mark Charsley <mcharsley(at)google(dot)com> writes:
> This line
> https://github.com/postgres/postgres/blob/30012a04a6c8127397a8ab71e160d9c7e7fbe874/src/interfaces/libpq/fe-exec.c#L1073
> triggers data race errors when run under ThreadSanitizer (*)

> As far as I can tell, the static variable in question is a hack to allow a
> couple of deprecated functions that are already unsafe to use
> (PQescapeString and PQescapeBytea) to be fractionally less unsafe to use.

Yup.

> Would there be any interest in a patch changing the type of
> static_client_coding
> and static_std_strings
> <https://github.com/postgres/postgres/blob/30012a04a6c8127397a8ab71e160d9c7e7fbe874/src/interfaces/libpq/fe-exec.c#L49>
> to
> some atomic equivalent, so the data race goes away?

I don't see that making those be some other datatype would improve anything
usefully. (1) On just about every platform known to man, int and bool are
going to be atomic anyway. (2) The *actual* hazards here, as opposed to
theoretical ones, are that you're using more than one connection with
different settings for these values, whereupon it's not clear whether
those deprecated functions will see the appropriate settings when they're
used. A different data type won't help that.

In short: this warning you're getting from ThreadSanitizer is entirely
off-point, so contorting the code to suppress it seems useless.

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Fujii Masao 2020-01-30 17:00:21 Re: recovery_target_action=pause with confusing hint
Previous Message Fujii Masao 2020-01-30 16:28:38 Re: table partitioning and access privileges