Configure with thread sanitizer fails the thread test

2021-07-23 Thread Mikhail Matrosov
This is a reply to an old thread with the same name:
https://www.postgresql.org/message-id/1513971675.5870501.1439797066345.javamail.ya...@mail.yahoo.com
I was not able to do a proper reply since I cannot download the raw
message: https://postgrespro.com/list/thread-id/2483942

Anyway, the problem with thread sanitizer is still present. If I try to
build libpq v13.3 with thread sanitizer, I get a configuration error like
this:

configure:18852: checking thread safety of required library functions
configure:18875: /usr/bin/clang-12 -o conftest -Wall -Wmissing-prototypes
-Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels
-Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv
-Wno-unused-command-line-argument -m64 -O3 -fsanitize=thread -pthread
-D_REENTRANT -D_THREAD_SAFE -D_POSIX_PTHREAD_SEMANTICS -DIN_CONFIGURE
-I/home/mmatrosov/.conan/data/zlib/1.2.11/_/_/package/98c3afaf7dd035538c92258b227714d9d4a19852/include
-DNDEBUG -D_GNU_SOURCE  -m64
-L/home/mmatrosov/.conan/data/zlib/1.2.11/_/_/package/98c3afaf7dd035538c92258b227714d9d4a19852/lib
 conftest.c -lz -lm -lz  >&5
configure:18875: $? = 0
configure:18875: ./conftest
==
WARNING: ThreadSanitizer: data race (pid=3413987)
  Write of size 4 at 0x00f1744c by thread T2:
#0 func_call_2  (conftest+0x4b5e51)

  Previous read of size 4 at 0x00f1744c by thread T1:
#0 func_call_1  (conftest+0x4b5d12)

  Location is global 'errno2_set' of size 4 at 0x00f1744c
(conftest+0x00f1744c)

  Thread T2 (tid=3413990, running) created by main thread at:
#0 pthread_create  (conftest+0x424b3b)
#1 main  (conftest+0x4b5b49)

  Thread T1 (tid=3413989, running) created by main thread at:
#0 pthread_create  (conftest+0x424b3b)
#1 main  (conftest+0x4b5b2e)

...

configure:18879: result: no
configure:18881: error: thread test program failed
This platform is not thread-safe.  Check the file 'config.log' or compile
and run src/test/thread/thread_test for the exact reason.
Use --disable-thread-safety to disable thread safety.


I am not sure what is the proper fix for the issue, but I at least suggest
to disable this test when building with thread sanitizer:
https://github.com/conan-io/conan-center-index/pull/6472/files#diff-b8639f81e30f36c8ba29a0878f1ef4d9f1552293bc9098ebb9b429ddb1f0935f

-
Best regards, Mikhail Matrosov


Re: Configure with thread sanitizer fails the thread test

2021-07-25 Thread Mikhail Matrosov
Hi, Alvaro and all,

> this patch hasn't been posted by the author so let's assume
> they're not authorizing them to use it.

Not sure what you mean. I am the author and I authorize anyone to do
whatever they want with it.

> Otherwise, why wouldn't they just post it here instead of doing the
absurdly convoluted dance of a github PR?

Well, for me submitting a github PR is a well-established and easy-to-do
procedure which is the same for all libraries. Posting to a new mailing
list definitely is not. I've spent around 15 minutes trying to do a proper
reply to the thread and did not succeed.

Another reason to post a PR is that we consume libpq via conan, and
releasing a new revision of the conan recipe for the same library version
is a relatively fast and well-defined process. While waiting for a new
version of a library with a patch depends heavily on a particular library.
I am not aware of the release cadence of libpq.

Anyway, I am very glad there is swift feedback from you guys and I am
looking forward to your comments on the proper way to fix the issue!

-----
Best regards, Mikhail Matrosov