hpcloud / tail

Go package for reading from continously updated files (tail -f)
MIT License
2.71k stars 503 forks source link

File (descriptor) not closed upon deletion #134

Open idanya opened 6 years ago

idanya commented 6 years ago

I am tailing a file that at some point (while tailing) gets deleted. I don't use reopen option, when the file is deleted I expect the tail to stop. The tail really stops, but I can see the file descriptor is not. when running lsof I can see all files tailed with a "(deleted)" string at the end.

Seems weird as tailFileSync starts with defer tail.close() and when the file gets deleted an ErrStop is raised and should just cause a return (triggering the defer). What am I missing?

lelikg commented 6 years ago

+1

zhoufang-joe commented 5 years ago

The tail only detect changes after reaching to the EOF. If you do not consume the tail.Lines chan, the sendLine func will be blocked. The tail may not be able to reach to the EOF, thus cannot detect the file deletion change.

idanya commented 5 years ago

I can see that sendLine is blocking with the chan, but assuming I will eventually process all chan lines (and I do), the tail loop will try to read the next line and will fail, causing the loop to end with tail.Killf(). This should close the file descriptor/reader, isn't it?