jenkinsci / lib-file-leak-detector

Java agent that detects file handle leak
http://file-leak-detector.kohsuke.org/
MIT License
241 stars 112 forks source link

Fix incorrect trace output upon file closing #38

Closed blindpirate closed 1 year ago

blindpirate commented 5 years ago

Previously when a file close callback is invoked, the dumped trace is not the closing stacktrace, but the opening stacktrace. This PR fixes this issue by creating a new FileRecord instance.

kohsuke commented 5 years ago

Interesting. For me, the original was the expected behaviour. Maybe we need to print both open & close.

blindpirate commented 5 years ago

With the "expected" behavior, it's difficult to track when a file is closed - the "open" stacktrace is printed at the "close" point. I strongly recommend changing to this PR's behaviour because it's really helpful in my practice.

kohsuke commented 5 years ago

Thanks, please help me understand your practice a bit more.

blindpirate commented 5 years ago

My case was that in a large application there're some file handler leaks. I applied this library to my application and printed all open/close log to a file. When analyzing the log file, I noticed that I couldn't find out where the files were closed - for example, you see a file opened twice but only closed once, and the close() code can be invoked in two (or more) places, without closing stacktrace I can't understand where it's closed and where it's not closed.

Hope this makes sense.

kohsuke commented 5 years ago

That makes total sense, thank you!!

MarkEWaite commented 1 year ago

Closing in favor of #132