Opened 11 years ago

Last modified 7 years ago

#861 closed defect (Fixed)

tor doesn't release log fd on hup if log failed

Reported by: arma Owned by:
Priority: Low Milestone:
Component: Core Tor/Tor Version: 0.2.0.31
Severity: Keywords:
Cc: arma, coderman, nickm Actual Points:
Parent ID: Points:
Reviewer: Sponsor:

Description

If my disk fills up and Tor's log stops (write failed or the like), then Tor
handles it fine -- it doesn't die:

% lsof|grep tord
tor 18060 arma 16w REG 3,5 11517952 782436 /tmp/tord-log

But when I hup tor, I get two handles:

tor 18060 arma 9w REG 3,5 11517952 782436 /tmp/tord-log
tor 18060 arma 16w REG 3,5 11517952 782436 /tmp/tord-log

I deleted tord-log, and I still have the handles (makes sense):
tor 18060 arma 9w REG 3,5 11517952 782436 /tmp/tord-log (deleted)
tor 18060 arma 16w REG 3,5 11517952 782436 /tmp/tord-log (deleted)

But then I hup tor and they're still here:
tor 18060 arma 9w REG 3,5 11517952 782436 /tmp/tord-log (deleted)
tor 18060 arma 16w REG 3,5 11517952 782436 /tmp/tord-log (deleted)
tor 18060 arma 20w REG 3,5 0 783109 /tmp/tord-log

It only happens when I'm out of disk space. So presumably there's something about
our seems_dead log entries that makes them not get cleaned when Tor hups.

Bug affects both 0.2.0.x and 0.2.1.x. I didn't check 0.1.2.x.

[Automatically added by flyspray2trac: Operating System: All]

Child Tickets

Change History (6)

comment:1 Changed 11 years ago by arma

Bug 222 may be relevant. As might r10395. Or not. :)

comment:2 Changed 11 years ago by nickm

Looking at the code! I don't think we don't do anything close/open-related differently on seems_dead.

Here's a possible chain of events:

  • We call fclose()
  • fclose() calls fflush()
  • fflush() calls write(), which fails with ENOSPC.
  • fflush() returns with an error
  • fclose() returns with an error without ever actually closing the fd.

I can't confirm from the glibc source whether they really do this, since the glibc source here is really hairy.

I'm not sure atm of the right solution here. We could stop using stdio for logs, I guess.

comment:3 Changed 11 years ago by nickm

The above etiology seems likeliest to me. fclose does indeed call fflush, and my fclose manpage says that fclose
can fail for any of the reasons that close(), write(), and fflush() can. The manpage also says that (succeed or
fail), future calls to fclose() are invalid.

We don't actually do any buffering on the file, so switching to fd-based files for logs seems smartest.

comment:4 Changed 11 years ago by nickm

Fixed in r17456, I hope. ;)

comment:5 Changed 11 years ago by nickm

flyspray2trac: bug closed.

comment:6 Changed 7 years ago by nickm

Component: Tor ClientTor
Note: See TracTickets for help on using tickets.