pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pgsql: Avoid holding a directory FD open across pg_ls_dir_files() calls
10+ messages / 1 participants
[nested] [flat]

* pgsql: Avoid holding a directory FD open across pg_ls_dir_files() calls
@ 2020-03-11 19:28  Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 10+ messages in thread

From: Tom Lane @ 2020-03-11 19:28 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Avoid holding a directory FD open across pg_ls_dir_files() calls.

This coding technique is undesirable because (a) it leaks the FD for
the rest of the transaction if the SRF is not run to completion, and
(b) allocated FDs are a scarce resource, but multiple interleaved
uses of the relevant functions could eat many such FDs.

In v11 and later, a query such as "SELECT pg_ls_waldir() LIMIT 1"
yields a warning about the leaked FD, and the only reason there's
no warning in earlier branches is that fd.c didn't whine about such
leaks before commit 9cb7db3f0.  Even disregarding the warning, it
wouldn't be too hard to run a backend out of FDs with careless use
of these SQL functions.

Hence, rewrite the function so that it reads the directory within
a single call, returning the results as a tuplestore rather than
via value-per-call mode.

There are half a dozen other built-in SRFs with similar problems,
but let's fix this one to start with, just to see if the buildfarm
finds anything wrong with the code.

In passing, fix bogus error report for stat() failure: it was
whining about the directory when it should be fingering the
individual file.  Doubtless a copy-and-paste error.

Back-patch to v10 where this function was added.

Justin Pryzby, with cosmetic tweaks and test cases by me

Discussion: https://postgr.es/m/20200308173103.GC1357@telsasoft.com

Branch
------
REL_11_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/63b51dfec18eb3c280adfa0f6e970946c441f574

Modified Files
--------------
src/backend/utils/adt/genfile.c              | 83 ++++++++++++++--------------
src/test/regress/expected/misc_functions.out | 40 ++++++++++++++
src/test/regress/sql/misc_functions.sql      | 18 ++++++
3 files changed, 100 insertions(+), 41 deletions(-)



^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* pgsql: Avoid holding a directory FD open across pg_ls_dir_files() calls
@ 2020-03-11 19:28  Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 10+ messages in thread

From: Tom Lane @ 2020-03-11 19:28 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Avoid holding a directory FD open across pg_ls_dir_files() calls.

This coding technique is undesirable because (a) it leaks the FD for
the rest of the transaction if the SRF is not run to completion, and
(b) allocated FDs are a scarce resource, but multiple interleaved
uses of the relevant functions could eat many such FDs.

In v11 and later, a query such as "SELECT pg_ls_waldir() LIMIT 1"
yields a warning about the leaked FD, and the only reason there's
no warning in earlier branches is that fd.c didn't whine about such
leaks before commit 9cb7db3f0.  Even disregarding the warning, it
wouldn't be too hard to run a backend out of FDs with careless use
of these SQL functions.

Hence, rewrite the function so that it reads the directory within
a single call, returning the results as a tuplestore rather than
via value-per-call mode.

There are half a dozen other built-in SRFs with similar problems,
but let's fix this one to start with, just to see if the buildfarm
finds anything wrong with the code.

In passing, fix bogus error report for stat() failure: it was
whining about the directory when it should be fingering the
individual file.  Doubtless a copy-and-paste error.

Back-patch to v10 where this function was added.

Justin Pryzby, with cosmetic tweaks and test cases by me

Discussion: https://postgr.es/m/20200308173103.GC1357@telsasoft.com

Branch
------
REL_10_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/05283dd5b5792b094b8211d46fef1082d411e679

Modified Files
--------------
src/backend/utils/adt/genfile.c              | 85 ++++++++++++++--------------
src/test/regress/expected/misc_functions.out | 43 ++++++++++++++
src/test/regress/sql/misc_functions.sql      | 21 +++++++
3 files changed, 107 insertions(+), 42 deletions(-)



^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* pgsql: Avoid holding a directory FD open across pg_ls_dir_files() calls
@ 2020-03-11 19:28  Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 10+ messages in thread

From: Tom Lane @ 2020-03-11 19:28 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Avoid holding a directory FD open across pg_ls_dir_files() calls.

This coding technique is undesirable because (a) it leaks the FD for
the rest of the transaction if the SRF is not run to completion, and
(b) allocated FDs are a scarce resource, but multiple interleaved
uses of the relevant functions could eat many such FDs.

In v11 and later, a query such as "SELECT pg_ls_waldir() LIMIT 1"
yields a warning about the leaked FD, and the only reason there's
no warning in earlier branches is that fd.c didn't whine about such
leaks before commit 9cb7db3f0.  Even disregarding the warning, it
wouldn't be too hard to run a backend out of FDs with careless use
of these SQL functions.

Hence, rewrite the function so that it reads the directory within
a single call, returning the results as a tuplestore rather than
via value-per-call mode.

There are half a dozen other built-in SRFs with similar problems,
but let's fix this one to start with, just to see if the buildfarm
finds anything wrong with the code.

In passing, fix bogus error report for stat() failure: it was
whining about the directory when it should be fingering the
individual file.  Doubtless a copy-and-paste error.

Back-patch to v10 where this function was added.

Justin Pryzby, with cosmetic tweaks and test cases by me

Discussion: https://postgr.es/m/20200308173103.GC1357@telsasoft.com

Branch
------
REL_12_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/3c8864fc1c54d6d58a65f07a306a9c874551d13d

Modified Files
--------------
src/backend/utils/adt/genfile.c              | 97 +++++++++++++++-------------
src/test/regress/expected/misc_functions.out | 46 +++++++++++++
src/test/regress/sql/misc_functions.sql      | 20 ++++++
3 files changed, 118 insertions(+), 45 deletions(-)



^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* pgsql: Avoid holding a directory FD open across pg_ls_dir_files() calls
@ 2020-03-11 19:28  Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 10+ messages in thread

From: Tom Lane @ 2020-03-11 19:28 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Avoid holding a directory FD open across pg_ls_dir_files() calls.

This coding technique is undesirable because (a) it leaks the FD for
the rest of the transaction if the SRF is not run to completion, and
(b) allocated FDs are a scarce resource, but multiple interleaved
uses of the relevant functions could eat many such FDs.

In v11 and later, a query such as "SELECT pg_ls_waldir() LIMIT 1"
yields a warning about the leaked FD, and the only reason there's
no warning in earlier branches is that fd.c didn't whine about such
leaks before commit 9cb7db3f0.  Even disregarding the warning, it
wouldn't be too hard to run a backend out of FDs with careless use
of these SQL functions.

Hence, rewrite the function so that it reads the directory within
a single call, returning the results as a tuplestore rather than
via value-per-call mode.

There are half a dozen other built-in SRFs with similar problems,
but let's fix this one to start with, just to see if the buildfarm
finds anything wrong with the code.

In passing, fix bogus error report for stat() failure: it was
whining about the directory when it should be fingering the
individual file.  Doubtless a copy-and-paste error.

Back-patch to v10 where this function was added.

Justin Pryzby, with cosmetic tweaks and test cases by me

Discussion: https://postgr.es/m/20200308173103.GC1357@telsasoft.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/085b6b6679e73b9b386f209b4d625c7bc60597c0

Modified Files
--------------
src/backend/utils/adt/genfile.c              | 97 +++++++++++++++-------------
src/test/regress/expected/misc_functions.out | 46 +++++++++++++
src/test/regress/sql/misc_functions.sql      | 20 ++++++
3 files changed, 118 insertions(+), 45 deletions(-)



^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* pgsql: Avoid holding a directory FD open across assorted SRF calls.
@ 2020-03-17 01:06  Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 10+ messages in thread

From: Tom Lane @ 2020-03-17 01:06 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Avoid holding a directory FD open across assorted SRF calls.

This extends the fixes made in commit 085b6b667 to other SRFs with the
same bug, namely pg_logdir_ls(), pgrowlocks(), pg_timezone_names(),
pg_ls_dir(), and pg_tablespace_databases().

Also adjust various comments and documentation to warn against
expecting to clean up resources during a ValuePerCall SRF's final
call.

Back-patch to all supported branches, since these functions were
all born broken.

Justin Pryzby, with cosmetic tweaks by me

Discussion: https://postgr.es/m/20200308173103.GC1357@telsasoft.com

Branch
------
REL_10_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/5e4a0b7194b9b53eeedc718fde1430eb649b8b62

Modified Files
--------------
contrib/adminpack/adminpack.c                |  80 +++++++------
contrib/pgrowlocks/pgrowlocks.c              | 164 ++++++++++++---------------
doc/src/sgml/xfunc.sgml                      |  98 ++++++++++------
src/backend/utils/adt/datetime.c             | 101 +++++++----------
src/backend/utils/adt/genfile.c              | 109 +++++++++---------
src/backend/utils/adt/misc.c                 | 127 +++++++++++----------
src/backend/utils/fmgr/README                |  16 ++-
src/include/funcapi.h                        |  13 ++-
src/test/regress/expected/misc_functions.out |  21 ++++
src/test/regress/sql/misc_functions.sql      |   9 ++
10 files changed, 391 insertions(+), 347 deletions(-)



^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* pgsql: Avoid holding a directory FD open across assorted SRF calls.
@ 2020-03-17 01:06  Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 10+ messages in thread

From: Tom Lane @ 2020-03-17 01:06 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Avoid holding a directory FD open across assorted SRF calls.

This extends the fixes made in commit 085b6b667 to other SRFs with the
same bug, namely pg_logdir_ls(), pgrowlocks(), pg_timezone_names(),
pg_ls_dir(), and pg_tablespace_databases().

Also adjust various comments and documentation to warn against
expecting to clean up resources during a ValuePerCall SRF's final
call.

Back-patch to all supported branches, since these functions were
all born broken.

Justin Pryzby, with cosmetic tweaks by me

Discussion: https://postgr.es/m/20200308173103.GC1357@telsasoft.com

Branch
------
REL9_5_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/da254148f4deff3cc5f4a5003e5b3c026c04f4a9

Modified Files
--------------
contrib/adminpack/adminpack.c    |  80 ++++++++++++------------
contrib/pgrowlocks/pgrowlocks.c  | 124 ++++++++++++++++--------------------
doc/src/sgml/xfunc.sgml          |  98 ++++++++++++++++++-----------
src/backend/utils/adt/datetime.c | 101 ++++++++++++------------------
src/backend/utils/adt/genfile.c  | 105 ++++++++++++++++---------------
src/backend/utils/adt/misc.c     | 131 +++++++++++++++++++++------------------
src/backend/utils/fmgr/README    |  16 +++--
src/include/funcapi.h            |  13 +++-
8 files changed, 342 insertions(+), 326 deletions(-)



^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* pgsql: Avoid holding a directory FD open across assorted SRF calls.
@ 2020-03-17 01:06  Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 10+ messages in thread

From: Tom Lane @ 2020-03-17 01:06 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Avoid holding a directory FD open across assorted SRF calls.

This extends the fixes made in commit 085b6b667 to other SRFs with the
same bug, namely pg_logdir_ls(), pgrowlocks(), pg_timezone_names(),
pg_ls_dir(), and pg_tablespace_databases().

Also adjust various comments and documentation to warn against
expecting to clean up resources during a ValuePerCall SRF's final
call.

Back-patch to all supported branches, since these functions were
all born broken.

Justin Pryzby, with cosmetic tweaks by me

Discussion: https://postgr.es/m/20200308173103.GC1357@telsasoft.com

Branch
------
REL_12_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/2a89455aade3e917b6b0d02d9ce385049d0525eb

Modified Files
--------------
contrib/adminpack/adminpack.c                |  80 ++++++-------
contrib/pgrowlocks/pgrowlocks.c              | 173 ++++++++++++---------------
doc/src/sgml/xfunc.sgml                      |  96 +++++++++------
src/backend/utils/adt/datetime.c             | 101 +++++++---------
src/backend/utils/adt/genfile.c              | 112 ++++++++---------
src/backend/utils/adt/misc.c                 | 117 ++++++++++--------
src/backend/utils/fmgr/README                |  16 ++-
src/include/funcapi.h                        |  13 +-
src/test/regress/expected/misc_functions.out |  21 ++++
src/test/regress/sql/misc_functions.sql      |   9 ++
10 files changed, 389 insertions(+), 349 deletions(-)



^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* pgsql: Avoid holding a directory FD open across assorted SRF calls.
@ 2020-03-17 01:06  Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 10+ messages in thread

From: Tom Lane @ 2020-03-17 01:06 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Avoid holding a directory FD open across assorted SRF calls.

This extends the fixes made in commit 085b6b667 to other SRFs with the
same bug, namely pg_logdir_ls(), pgrowlocks(), pg_timezone_names(),
pg_ls_dir(), and pg_tablespace_databases().

Also adjust various comments and documentation to warn against
expecting to clean up resources during a ValuePerCall SRF's final
call.

Back-patch to all supported branches, since these functions were
all born broken.

Justin Pryzby, with cosmetic tweaks by me

Discussion: https://postgr.es/m/20200308173103.GC1357@telsasoft.com

Branch
------
REL9_6_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/cd6a0518794d939ed6a716c1a13ead2900b11d50

Modified Files
--------------
contrib/adminpack/adminpack.c                |  80 ++++++++---------
contrib/pgrowlocks/pgrowlocks.c              | 124 +++++++++++---------------
doc/src/sgml/xfunc.sgml                      |  98 +++++++++++++--------
src/backend/utils/adt/datetime.c             | 101 +++++++++------------
src/backend/utils/adt/genfile.c              | 105 +++++++++++-----------
src/backend/utils/adt/misc.c                 | 127 +++++++++++++++------------
src/backend/utils/fmgr/README                |  16 ++--
src/include/funcapi.h                        |  13 ++-
src/test/regress/expected/misc_functions.out |  27 ++++++
src/test/regress/sql/misc_functions.sql      |  15 ++++
10 files changed, 382 insertions(+), 324 deletions(-)



^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* pgsql: Avoid holding a directory FD open across assorted SRF calls.
@ 2020-03-17 01:06  Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 10+ messages in thread

From: Tom Lane @ 2020-03-17 01:06 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Avoid holding a directory FD open across assorted SRF calls.

This extends the fixes made in commit 085b6b667 to other SRFs with the
same bug, namely pg_logdir_ls(), pgrowlocks(), pg_timezone_names(),
pg_ls_dir(), and pg_tablespace_databases().

Also adjust various comments and documentation to warn against
expecting to clean up resources during a ValuePerCall SRF's final
call.

Back-patch to all supported branches, since these functions were
all born broken.

Justin Pryzby, with cosmetic tweaks by me

Discussion: https://postgr.es/m/20200308173103.GC1357@telsasoft.com

Branch
------
REL_11_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/819d5525744bff600b6073804a7a5eb7a9342a8b

Modified Files
--------------
contrib/adminpack/adminpack.c                |  80 +++++++------
contrib/pgrowlocks/pgrowlocks.c              | 164 ++++++++++++---------------
doc/src/sgml/xfunc.sgml                      |  96 ++++++++++------
src/backend/utils/adt/datetime.c             | 101 +++++++----------
src/backend/utils/adt/genfile.c              | 109 +++++++++---------
src/backend/utils/adt/misc.c                 | 117 ++++++++++---------
src/backend/utils/fmgr/README                |  16 ++-
src/include/funcapi.h                        |  13 ++-
src/test/regress/expected/misc_functions.out |  21 ++++
src/test/regress/sql/misc_functions.sql      |   9 ++
10 files changed, 385 insertions(+), 341 deletions(-)



^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* pgsql: Avoid holding a directory FD open across assorted SRF calls.
@ 2020-03-17 01:06  Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 10+ messages in thread

From: Tom Lane @ 2020-03-17 01:06 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Avoid holding a directory FD open across assorted SRF calls.

This extends the fixes made in commit 085b6b667 to other SRFs with the
same bug, namely pg_logdir_ls(), pgrowlocks(), pg_timezone_names(),
pg_ls_dir(), and pg_tablespace_databases().

Also adjust various comments and documentation to warn against
expecting to clean up resources during a ValuePerCall SRF's final
call.

Back-patch to all supported branches, since these functions were
all born broken.

Justin Pryzby, with cosmetic tweaks by me

Discussion: https://postgr.es/m/20200308173103.GC1357@telsasoft.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/b4570d33aa045df330bb325ba8a2cbf02266a555

Modified Files
--------------
contrib/adminpack/adminpack.c                |  78 ++++++------
contrib/pgrowlocks/pgrowlocks.c              | 173 ++++++++++++---------------
doc/src/sgml/xfunc.sgml                      |  96 +++++++++------
src/backend/utils/adt/datetime.c             | 101 +++++++---------
src/backend/utils/adt/genfile.c              | 112 ++++++++---------
src/backend/utils/adt/misc.c                 | 117 ++++++++++--------
src/backend/utils/fmgr/README                |  16 ++-
src/include/funcapi.h                        |  13 +-
src/test/regress/expected/misc_functions.out |  21 ++++
src/test/regress/sql/misc_functions.sql      |   9 ++
10 files changed, 388 insertions(+), 348 deletions(-)



^ permalink  raw  reply  [nested|flat] 10+ messages in thread


end of thread, other threads:[~2020-03-17 01:06 UTC | newest]

Thread overview: 10+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2020-03-11 19:28 pgsql: Avoid holding a directory FD open across pg_ls_dir_files() calls Tom Lane <tgl@sss.pgh.pa.us>
2020-03-11 19:28 pgsql: Avoid holding a directory FD open across pg_ls_dir_files() calls Tom Lane <tgl@sss.pgh.pa.us>
2020-03-11 19:28 pgsql: Avoid holding a directory FD open across pg_ls_dir_files() calls Tom Lane <tgl@sss.pgh.pa.us>
2020-03-11 19:28 pgsql: Avoid holding a directory FD open across pg_ls_dir_files() calls Tom Lane <tgl@sss.pgh.pa.us>
2020-03-17 01:06 pgsql: Avoid holding a directory FD open across assorted SRF calls. Tom Lane <tgl@sss.pgh.pa.us>
2020-03-17 01:06 pgsql: Avoid holding a directory FD open across assorted SRF calls. Tom Lane <tgl@sss.pgh.pa.us>
2020-03-17 01:06 pgsql: Avoid holding a directory FD open across assorted SRF calls. Tom Lane <tgl@sss.pgh.pa.us>
2020-03-17 01:06 pgsql: Avoid holding a directory FD open across assorted SRF calls. Tom Lane <tgl@sss.pgh.pa.us>
2020-03-17 01:06 pgsql: Avoid holding a directory FD open across assorted SRF calls. Tom Lane <tgl@sss.pgh.pa.us>
2020-03-17 01:06 pgsql: Avoid holding a directory FD open across assorted SRF calls. Tom Lane <tgl@sss.pgh.pa.us>

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