Re: connection failures on forked processes

From: Justin Pryzby <pryzby(at)telsasoft(dot)com>
To: Jim Popovitch <jim(dot)popovitch(at)replatformtech(dot)com>
Cc: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: connection failures on forked processes
Date: 2022-06-12 14:57:00
Message-ID: 20220612145659.GD29853@telsasoft.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Sun, Jun 12, 2022 at 10:05:59AM -0400, Jim Popovitch wrote:
> We are seeing connection failures when using "sslmode=require" on forked
> connections. Attached is example code that makes 2 passes. The first pass
> uses "sslmode=disable" and the second uses "sslmode=require". The first
> pass completes successfully, but the second pass fails. I'm looking for
> insight as to why this might be happening.

The child's connection works fine, but the grandchild's connection doesn't.

The most obvious reason is that the first child exits which tears down the SSL
connection in a way that doesn't allow sending more data on it (maybe as a
deliberate security measure).

You'll see the same failure in both cases if you PQfinish() after PQclear().

> Note: we are very aware of the dev notes about forking, however know that
> we are not sharing the forked connection, we simply open the connection in
> the parent thread and then pass that to the child thread to use.

In case there is any doubt: processes are not threads.
(Also, I don't think the phrase "parent thread" is more misleading than
accurate, although I'm sure some people use it.)

--
Justin

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2022-06-12 15:24:37 Re: Quick question regarding HeapTupleHeaderData.t_ctid
Previous Message Andrew Dunstan 2022-06-12 14:19:23 Re: Subscription tests vs log_error_verbosity