pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
[PATCH v3 2/4] wip: llvmjit: remove unnecessary types.
7+ messages / 4 participants
[nested] [flat]

* [PATCH v3 2/4] wip: llvmjit: remove unnecessary types.
@ 2022-11-01 05:35 Andres Freund <andres@anarazel.de>
  0 siblings, 0 replies; 7+ messages in thread

From: Andres Freund @ 2022-11-01 05:35 UTC (permalink / raw)

---
 src/backend/jit/llvm/llvmjit.c | 11 -----------
 1 file changed, 11 deletions(-)

diff --git a/src/backend/jit/llvm/llvmjit.c b/src/backend/jit/llvm/llvmjit.c
index 8d01a077d1c..360de20ebee 100644
--- a/src/backend/jit/llvm/llvmjit.c
+++ b/src/backend/jit/llvm/llvmjit.c
@@ -61,23 +61,12 @@ LLVMTypeRef TypeParamBool;
 LLVMTypeRef TypeStorageBool;
 LLVMTypeRef TypePGFunction;
 LLVMTypeRef StructNullableDatum;
-LLVMTypeRef StructHeapTupleFieldsField3;
-LLVMTypeRef StructHeapTupleFields;
-LLVMTypeRef StructHeapTupleHeaderData;
-LLVMTypeRef StructHeapTupleDataChoice;
 LLVMTypeRef StructHeapTupleData;
-LLVMTypeRef StructMinimalTupleData;
-LLVMTypeRef StructItemPointerData;
-LLVMTypeRef StructBlockId;
-LLVMTypeRef StructFormPgAttribute;
-LLVMTypeRef StructTupleConstr;
 LLVMTypeRef StructTupleDescData;
 LLVMTypeRef StructTupleTableSlot;
 LLVMTypeRef StructHeapTupleTableSlot;
 LLVMTypeRef StructMinimalTupleTableSlot;
 LLVMTypeRef StructMemoryContextData;
-LLVMTypeRef StructPGFinfoRecord;
-LLVMTypeRef StructFmgrInfo;
 LLVMTypeRef StructFunctionCallInfoData;
 LLVMTypeRef StructExprContext;
 LLVMTypeRef StructExprEvalStep;
-- 
2.38.0


--ujwq2ejpw4d4bq5o
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
	filename="v3-0003-wip-llvmjit-Make-llvm_types_module-variable-stati.patch"



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* BUG #18312: libpq: PQsetdbLogin() not thread-safe
@ 2024-01-26 10:06 PG Bug reporting form <noreply@postgresql.org>
  2024-02-02 16:27 ` Re: BUG #18312: libpq: PQsetdbLogin() not thread-safe Christian Maurer <c.maurer@gmx.at>
  0 siblings, 1 reply; 7+ messages in thread

From: PG Bug reporting form @ 2024-01-26 10:06 UTC (permalink / raw)
  To: pgsql-bugs@lists.postgresql.org; +Cc: c.maurer@gmx.at

The following bug has been logged on the website:

Bug reference:      18312
Logged by:          Christian Maurer
Email address:      c.maurer@gmx.at
PostgreSQL version: 16.1
Operating system:   Windows 10 Pro
Description:        

Hi

When calling PQsetdbLogin() concurrently the program crashes with RC=3.

Server: PostgreSQL 16.1 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 11.4.1
20230605 (Red Hat 11.4.1-2), 64-bit
libpq: postgresql-16.1-1-windows-x64-binaries.zip (coming from
https://www.enterprisedb.com/download-postgresql-binaries)

Output:
PQisthreadsafe: 1
Connect 0
Connect 2
Connect 1
Connect 3
Connected 0
Connected 2
Finished 0
Finished 2
=> 'End' was not reached
=> %ERRORLEVEL% is 3
=> Thread 1 and 3 did not connect/finish

When calling PQsetdbLogin() and PQfinish() once before the multi-threading
starts, there is no crash and we get the expected output:
PQisthreadsafe: 1
Connect 0
Connect 2
Connect 3
Connect 1
Connected 3
Finished 3
Connected 1
Finished 1
Connected 2
Connected 0
Finished 2
Finished 0
End

Regards
Christian

-- main.cpp start --
#include <iostream>
#include <thread>
#include <vector>
#include <pgsql/libpq-fe.h>

void test(int i)
{
    try {
        std::cout << "Connect " << i << std::endl;
        PGconn *pgConn = PQsetdbLogin("myHost", (const char*)NULL, (const
char*)NULL, (const char*)NULL, "myDatabase", "myUser", "myPassword");
        std::cout << "Connected " << i << std::endl;
        PQfinish(pgConn);
        std::cout << "Finished " << i << std::endl;
    }
    catch (...)
    {
        std::cout << "Exception occurred in " << i << std::endl;
    }
}

int main()
{
    try {
        std::cout << "PQisthreadsafe: " << PQisthreadsafe() << std::endl;

        //PGconn* pgConn = PQsetdbLogin("myHost", (const char*)NULL, (const
char*)NULL, (const char*)NULL, "myDatabase", "myUser", "myPassword");
        //PQfinish(pgConn);

        const std::size_t maxThreads = 4U;
        std::vector<std::thread> myThreads;
        for (std::size_t i = 0; i < maxThreads; ++i)
            myThreads.push_back(std::thread(test, i));

        for (std::thread& myThread : myThreads)
            myThread.join();

        std::cout << "End" << std::endl;
    }
    catch (...)
    {
        std::cout << "Exception occurred in main" << std::endl;
    }

    return 0;
}
-- main.cpp end --



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: BUG #18312: libpq: PQsetdbLogin() not thread-safe
  2024-01-26 10:06 BUG #18312: libpq: PQsetdbLogin() not thread-safe PG Bug reporting form <noreply@postgresql.org>
@ 2024-02-02 16:27 ` Christian Maurer <c.maurer@gmx.at>
  2024-02-02 18:19   ` Re: BUG #18312: libpq: PQsetdbLogin() not thread-safe Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 7+ messages in thread

From: Christian Maurer @ 2024-02-02 16:27 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; pgsql-bugs@lists.postgresql.org


> I wondered whether we needed to introduce a critical section
> to prevent multiple threads from calling that concurrently,
> even though its docs allege you shouldn't have to. Perhaps
> it's thread-safe except on Windows?
This would explain, why I could not reproduce the error on Red Hat Enterprise Linux.
 
Regards,
Christian Maurer





^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: BUG #18312: libpq: PQsetdbLogin() not thread-safe
  2024-01-26 10:06 BUG #18312: libpq: PQsetdbLogin() not thread-safe PG Bug reporting form <noreply@postgresql.org>
  2024-02-02 16:27 ` Re: BUG #18312: libpq: PQsetdbLogin() not thread-safe Christian Maurer <c.maurer@gmx.at>
@ 2024-02-02 18:19   ` Tom Lane <tgl@sss.pgh.pa.us>
  2024-02-05 12:49     ` Re: BUG #18312: libpq: PQsetdbLogin() not thread-safe Christian Maurer <c.maurer@gmx.at>
  0 siblings, 1 reply; 7+ messages in thread

From: Tom Lane @ 2024-02-02 18:19 UTC (permalink / raw)
  To: Christian Maurer <c.maurer@gmx.at>; +Cc: pgsql-bugs@lists.postgresql.org

Christian Maurer <c.maurer@gmx.at> writes:
>> I wondered whether we needed to introduce a critical section
>> to prevent multiple threads from calling that concurrently,
>> even though its docs allege you shouldn't have to. Perhaps
>> it's thread-safe except on Windows?

> This would explain, why I could not reproduce the error on Red Hat Enterprise Linux.

Are you in a position to try a source-code patch?  The attached
is very quick-and-dirty, but if it resolves your problem then
we could turn it into something respectable.

			regards, tom lane

Attachments:

  [text/x-diff] avoid-concurrent-bindtextdomain-calls-wip.patch (578B, ../../3222816.1706897982@sss.pgh.pa.us/2-avoid-concurrent-bindtextdomain-calls-wip.patch)
  download | inline diff:
diff --git a/src/interfaces/libpq/fe-misc.c b/src/interfaces/libpq/fe-misc.c
index 47a28b0a3a..8906dae892 100644
--- a/src/interfaces/libpq/fe-misc.c
+++ b/src/interfaces/libpq/fe-misc.c
@@ -1243,12 +1243,17 @@ libpq_binddomain(void)
 #endif
 		const char *ldir;
 
+		pglock_thread();
+
 		/* No relocatable lookup here because the binary could be anywhere */
 		ldir = getenv("PGLOCALEDIR");
 		if (!ldir)
 			ldir = LOCALEDIR;
 		bindtextdomain(PG_TEXTDOMAIN("libpq"), ldir);
 		already_bound = true;
+
+		pgunlock_thread();
+
 #ifdef WIN32
 		SetLastError(save_errno);
 #else

^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: BUG #18312: libpq: PQsetdbLogin() not thread-safe
  2024-01-26 10:06 BUG #18312: libpq: PQsetdbLogin() not thread-safe PG Bug reporting form <noreply@postgresql.org>
  2024-02-02 16:27 ` Re: BUG #18312: libpq: PQsetdbLogin() not thread-safe Christian Maurer <c.maurer@gmx.at>
  2024-02-02 18:19   ` Re: BUG #18312: libpq: PQsetdbLogin() not thread-safe Tom Lane <tgl@sss.pgh.pa.us>
@ 2024-02-05 12:49     ` Christian Maurer <c.maurer@gmx.at>
  2024-02-05 15:24       ` Re: BUG #18312: libpq: PQsetdbLogin() not thread-safe Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 7+ messages in thread

From: Christian Maurer @ 2024-02-05 12:49 UTC (permalink / raw)
  To: pgsql-bugs@lists.postgresql.org, Tom Lane <tgl@sss.pgh.pa.us>

Hi Tom Lane,
 
I could apply your patch and compile libpq on Windows 10.
 
The parallel connect issues are gone now
* in the minimal example and
* also in our regression test which showed the issue in the first place.
 
Would it be possible, that the patch you are aiming to make can be included in version 16.2?
 
Regards,
Christian






^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: BUG #18312: libpq: PQsetdbLogin() not thread-safe
  2024-01-26 10:06 BUG #18312: libpq: PQsetdbLogin() not thread-safe PG Bug reporting form <noreply@postgresql.org>
  2024-02-02 16:27 ` Re: BUG #18312: libpq: PQsetdbLogin() not thread-safe Christian Maurer <c.maurer@gmx.at>
  2024-02-02 18:19   ` Re: BUG #18312: libpq: PQsetdbLogin() not thread-safe Tom Lane <tgl@sss.pgh.pa.us>
  2024-02-05 12:49     ` Re: BUG #18312: libpq: PQsetdbLogin() not thread-safe Christian Maurer <c.maurer@gmx.at>
@ 2024-02-05 15:24       ` Tom Lane <tgl@sss.pgh.pa.us>
  2024-02-05 20:05         ` Re: BUG #18312: libpq: PQsetdbLogin() not thread-safe Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 7+ messages in thread

From: Tom Lane @ 2024-02-05 15:24 UTC (permalink / raw)
  To: Christian Maurer <c.maurer@gmx.at>; +Cc: pgsql-bugs@lists.postgresql.org

Christian Maurer <c.maurer@gmx.at> writes:
> I could apply your patch and compile libpq on Windows 10.
>  
> The parallel connect issues are gone now
> * in the minimal example and
> * also in our regression test which showed the issue in the first place.

Great, thanks for the confirmation.

> Would it be possible, that the patch you are aiming to make can be included in version 16.2?

I'm afraid we're a few days too late for that --- even if I had
a finished patch, the release freeze started two days ago.
It'll be in the May releases, instead.

			regards, tom lane





^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: BUG #18312: libpq: PQsetdbLogin() not thread-safe
  2024-01-26 10:06 BUG #18312: libpq: PQsetdbLogin() not thread-safe PG Bug reporting form <noreply@postgresql.org>
  2024-02-02 16:27 ` Re: BUG #18312: libpq: PQsetdbLogin() not thread-safe Christian Maurer <c.maurer@gmx.at>
  2024-02-02 18:19   ` Re: BUG #18312: libpq: PQsetdbLogin() not thread-safe Tom Lane <tgl@sss.pgh.pa.us>
  2024-02-05 12:49     ` Re: BUG #18312: libpq: PQsetdbLogin() not thread-safe Christian Maurer <c.maurer@gmx.at>
  2024-02-05 15:24       ` Re: BUG #18312: libpq: PQsetdbLogin() not thread-safe Tom Lane <tgl@sss.pgh.pa.us>
@ 2024-02-05 20:05         ` Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 7+ messages in thread

From: Tom Lane @ 2024-02-05 20:05 UTC (permalink / raw)
  To: Christian Maurer <c.maurer@gmx.at>; +Cc: pgsql-bugs@lists.postgresql.org

I wrote:
> Christian Maurer <c.maurer@gmx.at> writes:
>> Would it be possible, that the patch you are aiming to make can be included in version 16.2?

> I'm afraid we're a few days too late for that --- even if I had
> a finished patch, the release freeze started two days ago.
> It'll be in the May releases, instead.

For the archives' sake --- I've posted a patch for this at [1].

			regards, tom lane

[1] https://www.postgresql.org/message-id/264860.1707163416%40sss.pgh.pa.us





^ permalink  raw  reply  [nested|flat] 7+ messages in thread


end of thread, other threads:[~2024-02-05 20:05 UTC | newest]

Thread overview: 7+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2022-11-01 05:35 [PATCH v3 2/4] wip: llvmjit: remove unnecessary types. Andres Freund <andres@anarazel.de>
2024-01-26 10:06 BUG #18312: libpq: PQsetdbLogin() not thread-safe PG Bug reporting form <noreply@postgresql.org>
2024-02-02 16:27 ` Re: BUG #18312: libpq: PQsetdbLogin() not thread-safe Christian Maurer <c.maurer@gmx.at>
2024-02-02 18:19   ` Re: BUG #18312: libpq: PQsetdbLogin() not thread-safe Tom Lane <tgl@sss.pgh.pa.us>
2024-02-05 12:49     ` Re: BUG #18312: libpq: PQsetdbLogin() not thread-safe Christian Maurer <c.maurer@gmx.at>
2024-02-05 15:24       ` Re: BUG #18312: libpq: PQsetdbLogin() not thread-safe Tom Lane <tgl@sss.pgh.pa.us>
2024-02-05 20:05         ` Re: BUG #18312: libpq: PQsetdbLogin() not thread-safe Tom Lane <tgl@sss.pgh.pa.us>

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