mdtruncate leaking fd.c handles?

Started by Andres Freundover 9 years ago4 messageshackers
Jump to latest
#1Andres Freund
andres@anarazel.de

Hi,

Am I missing something or is md.c:mdtruncate() leaking open files?
The relevant piece of code is:

if (priorblocks > nblocks)
{
/*
* This segment is no longer active (and has already been unlinked
* from the mdfd_chain). We truncate the file, but do not delete
* it, for reasons explained in the header comments.
*/
if (FileTruncate(v->mdfd_vfd, 0) < 0)
ereport(ERROR,
(errcode_for_file_access(),
errmsg("could not truncate file \"%s\": %m",
FilePathName(v->mdfd_vfd))));

if (!SmgrIsTemp(reln))
register_dirty_segment(reln, forknum, v);
v = v->mdfd_chain;
Assert(ov != reln->md_fd[forknum]); /* we never drop the 1st
* segment */
pfree(ov);
}

note that we're freeing the chain entry, which contains the mdfd_vfd,
without previously calling FileClose().

This only really matters for VACUUM truncate and ON COMMIT TRUNCATE temp
table truncation afaics. But it seems like we should fix it everywhere
nonetheless.

Greetings,

Andres Freund

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Andres Freund (#1)
Re: mdtruncate leaking fd.c handles?

Andres Freund <andres@anarazel.de> writes:

Am I missing something or is md.c:mdtruncate() leaking open files?

Yeah, I think you're right.

This only really matters for VACUUM truncate and ON COMMIT TRUNCATE temp
table truncation afaics.

Also, you'd need a table > 1GB to leak anything at all, which probably
helps explain why it hasn't been noticed.

regards, tom lane

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#3Andres Freund
andres@anarazel.de
In reply to: Tom Lane (#2)
Re: mdtruncate leaking fd.c handles?

On 2016-09-08 18:39:56 -0400, Tom Lane wrote:

Andres Freund <andres@anarazel.de> writes:

Am I missing something or is md.c:mdtruncate() leaking open files?

Yeah, I think you're right.

This only really matters for VACUUM truncate and ON COMMIT TRUNCATE temp
table truncation afaics.

Also, you'd need a table > 1GB to leak anything at all, which probably
helps explain why it hasn't been noticed.

Heh, this bug is of some older vintage... Appears to originate in
1a5c450f3024ac57cd6079186c71b3baf39e84eb - before that we did a
FileUnlink(), which includes a FileClose().

Will fix.

Andres

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#4Andres Freund
andres@anarazel.de
In reply to: Andres Freund (#3)
Re: mdtruncate leaking fd.c handles?

On 2016-09-08 15:50:42 -0700, Andres Freund wrote:

Andres Freund <andres@anarazel.de> writes:

Am I missing something or is md.c:mdtruncate() leaking open files?

Will fix.

And done.

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers