mdtruncate leaking fd.c handles?

From: Andres Freund <andres(at)anarazel(dot)de>
To: pgsql-hackers(at)postgresql(dot)org
Subject: mdtruncate leaking fd.c handles?
Date: 2016-09-08 22:07:48
Message-ID: 20160908220748.oqh37ukwqqncbl3n@alap3.anarazel.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

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

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2016-09-08 22:39:56 Re: mdtruncate leaking fd.c handles?
Previous Message Lucas 2016-09-08 22:07:11 Re: Preventing deadlock on parallel backup