Fix xlogreader fd leak encountered with twophase commit.
authorAndres Freund <[email protected]>
Tue, 7 Apr 2020 04:28:55 +0000 (21:28 -0700)
committerAndres Freund <[email protected]>
Tue, 7 Apr 2020 04:28:55 +0000 (21:28 -0700)
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[email protected]

src/backend/access/transam/xlogreader.c

index f3fea5132fe94d3fdc2f939c3191251017f75d81..79ff976474c76858cd6948311522ef7baa04ea78 100644 (file)
@@ -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)