ecpg PREPARE is not thread safe

From: ITAGAKI Takahiro <itagaki(dot)takahiro(at)oss(dot)ntt(dot)co(dot)jp>
To: pgsql-hackers(at)postgresql(dot)org
Subject: ecpg PREPARE is not thread safe
Date: 2007-09-21 02:05:47
Message-ID: 20070921103313.68C4.ITAGAKI.TAKAHIRO@oss.ntt.co.jp
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-patches

Hi,

I encountered segfaults in a multi-threaded ecpg application. It uses
PREPARE statements concurrently in several threads. The cause seems to
be the global variable 'prep_stmts' in ecpg/ecpglib/prepare.c .
It is accessed without any locks.

I'm trying to fix it, but there are some approaches to fix it.
1. Add a giant lock to protect prep_stmts.
2. Put prep_stmts into TSD (Thread Specific Data).
3. Put prep_stmts into connection specific data.

I think the proper approach is 3, because server-side prepared statements
are independent in each connection. For that matter, are there any problems
in current codes? Prepared statements are managed with a single list in it.
Even if we have some kinds of exclusive controls, current ecpg might not
good at prepared statements when we use multiple connections in a signle
thread or do multiple PREPARE in multiple threads. If so, 1 and 2 are not
correct fixes.

Regards,
---
ITAGAKI Takahiro
NTT Open Source Software Center

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2007-09-21 02:55:50 Re: HOT is applied
Previous Message Tom Lane 2007-09-21 01:55:02 Re: HOT is applied

Browse pgsql-patches by date

  From Date Subject
Next Message Magnus Hagander 2007-09-21 08:30:01 Re: [PATCHES] Patch to update log levels
Previous Message Tom Lane 2007-09-21 02:02:12 Re: adjust chr()/ascii() to prevent invalidly encoded data