Re: get_controlfile() can leak fds in the backend

Michael Paquier <michael@paquier.xyz>

From: Michael Paquier <michael@paquier.xyz>
To: Joe Conway <mail@joeconway.com>
Cc: Postgres hackers <pgsql-hackers@lists.postgresql.org>
Date: 2019-03-01T01:00:42Z
Lists: pgsql-hackers
On Thu, Feb 28, 2019 at 04:09:32PM -0500, Joe Conway wrote:
> Committed and push that way.

Thanks for committing a fix.

> By the way, while looking at this, I noted at least a couple of places
> where OpenTransientFile() is being passed O_RDWR when the usage is
> pretty clearly intended to be read-only. For example at least two
> instances in slru.c -- SlruPhysicalReadPage() and
> SimpleLruDoesPhysicalPageExist(). Is it worth while searching for and
> fixing those instances?

There are roughly 40~42 callers of OpenTransientFile().  Looking at
them I can see that RestoreSlotFromDisk() could also switch to RDONLY
instead of RDWR.  I am also a bit tired of the lack error handling
around CloseTransientFile().  While in some code paths the file
descriptors are closed for an error, in some others we should report
something.  I am going to send a patch after a lookup.  Let's see all
that on a separate thread.
--
Michael

Commits

  1. Tighten use of OpenTransientFile and CloseTransientFile

  2. Make get_controlfile not leak file descriptors