From: Andres Freund Date: Tue, 7 Apr 2020 04:28:55 +0000 (-0700) Subject: Fix xlogreader fd leak encountered with twophase commit. X-Git-Url: http://git.postgresql.org/gitweb/review?a=commitdiff_plain;h=c023bd7f2a85fe3f68bc7dd3eacfd912f70ffca7;p=users%2Fandresfreund%2Fpostgres.git Fix xlogreader fd leak encountered with twophase commit. This perhaps is not the best fix, but it's better than the current situation of failing after a few commits. This issue appeared after 0dc8ead46, but only because before that change fd leakage was limited to a single file descriptor. Discussion: https://postgr.es/m/20200406025651.fpzdb5yyb7qyhqko@alap3.anarazel.de --- diff --git a/src/backend/access/transam/xlogreader.c b/src/backend/access/transam/xlogreader.c index f3fea5132f..79ff976474 100644 --- a/src/backend/access/transam/xlogreader.c +++ b/src/backend/access/transam/xlogreader.c @@ -136,6 +136,9 @@ XLogReaderFree(XLogReaderState *state) { int block_id; + if (state->seg.ws_file != -1) + close(state->seg.ws_file); + for (block_id = 0; block_id <= XLR_MAX_BLOCK_ID; block_id++) { if (state->blocks[block_id].data)