pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Michael Paquier <michael@paquier.xyz>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Tighten use of OpenTransientFile and CloseTransientFile
Date: Fri, 08 Mar 2019 23:52:15 +0000
Message-ID: <E1h2PHj-0008GV-8I@gemulon.postgresql.org> (raw)

Tighten use of OpenTransientFile and CloseTransientFile

This fixes two sets of issues related to the use of transient files in
the backend:
1) OpenTransientFile() has been used in some code paths with read-write
flags while read-only is sufficient, so switch those calls to be
read-only where necessary.  These have been reported by Joe Conway.
2) When opening transient files, it is up to the caller to close the
file descriptors opened.  In error code paths, CloseTransientFile() gets
called to clean up things before issuing an error.  However in normal
exit paths, a lot of callers of CloseTransientFile() never actually
reported errors, which could leave a file descriptor open without
knowing about it.  This is an issue I complained about a couple of
times, but never had the courage to write and submit a patch, so here we
go.

Note that one frontend code path is impacted by this commit so as an
error is issued when fetching control file data, making backend and
frontend to be treated consistently.

Reported-by: Joe Conway, Michael Paquier
Author: Michael Paquier
Reviewed-by: Álvaro Herrera, Georgios Kokolatos, Joe Conway
Discussion: https://postgr.es/m/20190301023338.GD1348@paquier.xyz
Discussion: https://postgr.es/m/c49b69ec-e2f7-ff33-4f17-0eaa4f2cef27@joeconway.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/82a5649fb9dbef12d04cd24799be6bf298d889a6

Modified Files
--------------
contrib/pg_stat_statements/pg_stat_statements.c |  5 ++++-
src/backend/access/heap/rewriteheap.c           | 11 +++++++++--
src/backend/access/transam/slru.c               | 12 +++++++++---
src/backend/access/transam/timeline.c           |  8 +++++---
src/backend/access/transam/twophase.c           |  6 +++++-
src/backend/access/transam/xlog.c               |  5 ++++-
src/backend/libpq/be-fsstubs.c                  | 14 ++++++++++++--
src/backend/replication/logical/origin.c        | 12 ++++++++++--
src/backend/replication/logical/reorderbuffer.c |  5 ++++-
src/backend/replication/logical/snapbuild.c     | 11 +++++++++--
src/backend/replication/slot.c                  | 13 ++++++++++---
src/backend/replication/walsender.c             |  6 +++++-
src/backend/storage/file/copydir.c              |  5 ++++-
src/backend/storage/file/fd.c                   | 22 +++++++++++++++++++---
src/backend/storage/ipc/dsm_impl.c              | 10 +++++++++-
src/backend/utils/cache/relmapper.c             |  6 +++++-
src/common/controldata_utils.c                  | 13 +++++++++++--
17 files changed, 134 insertions(+), 30 deletions(-)



Message-ID: <E1h2PHj-0008GV-8I@gemulon.postgresql.org>
Permalink:  ../E1h2PHj-0008GV-8I@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1h2PHj-0008GV-8I@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: michael@paquier.xyz
  Subject: Re: pgsql: Tighten use of OpenTransientFile and CloseTransientFile
  In-Reply-To: <E1h2PHj-0008GV-8I@gemulon.postgresql.org>
  References: <E1h2PHj-0008GV-8I@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox