Thread: connection failures on forked processes

connection failures on forked processes

From
Jim Popovitch
Date:
Hello!

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.

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.

Thank you for any insight,

-Jim P.
Attachment

Re: connection failures on forked processes

From
Justin Pryzby
Date:
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