Re: BUG #17186: In connect.c, the lock connections_mutex is not correctly released(Line 463) at the return(Line 522)

Поиск
Список
Период
Сортировка
От Michael Paquier
Тема Re: BUG #17186: In connect.c, the lock connections_mutex is not correctly released(Line 463) at the return(Line 522)
Дата
Msg-id YTxA58Jtg5y6y+se@paquier.xyz
обсуждение исходный текст
Ответ на Re: BUG #17186: In connect.c, the lock connections_mutex is not correctly released(Line 463) at the return(Line 522)  (Michael Paquier <michael@paquier.xyz>)
Ответы Re: BUG #17186: In connect.c, the lock connections_mutex is not correctly released(Line 463) at the return(Line 522)  (Michael Paquier <michael@paquier.xyz>)
Список pgsql-bugs
On Fri, Sep 10, 2021 at 04:07:26PM +0900, Michael Paquier wrote:
> ecpg_alloc() is just a wrapper to calloc(), so errors are very
> unlikely going to happen in this code path.  It does not change the
> fact that it is wrong.  Nice catch, will fix.

After looking at the issue in depth, I have noticed that just
unlocking the pthread mutex is incorrect because we would still free a
connection object while is is *tracked* by the list of all the
connections.

In normal cases, we should just call ecpg_finish() to correctly clean
up the new connection from the list.  But I don't think that we need
to do any of that at this stage, and instead we had better move the
allocation for the connection parameters before doing the list
manipulation, saving from any cleanup action needed.  That also means
moving up a bit the calculations we do for connect_params when looking
at all the parameters.  And that means losing a log but as the
connection failed on OOM, it is not like we need to care anyway.

If a client is under memory pressure, that could really mess up
applications and the list of connections, so this had better be
backpatched.
--
Michael

Вложения

В списке pgsql-bugs по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: BUG #17158: Distinct ROW fails with Postgres 14
Следующее
От: Alexander Lakhin
Дата:
Сообщение: Re: BUG #17182: Race condition on concurrent DROP and CREATE of dependent object