anatol / smart.go

Pure-Go library to access drive's S.M.A.R.T. information

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

too many open files error when using smart.go in gotop client

rare-magma opened this issue · comments

commented

I'm integrating smart.go with gotop (cli activity monitor) to gather info about the disks temperature in a machine in this PR: xxxserxxx/gotop#221

Unfortunately after a few minutes, either smart.Open() or sm.ReadSMARTData() or sm.ReadSMART() end up causing a "too many open files" error.
Any idea on what might be the cause for this issue?

It might a file descriptor leak somewhere in the code.

Could you please:

  1. make sure you use the latest version of smart.go library. There was a file descriptor leak fixed not that far ago
  2. run your tool with strace -f $yourtool that reproduces the descriptor leak and post the last few hundred lines of the output?
  3. provide exact steps to reproduce the problem on my side

Also when the gotop starts reporting "too many files" please run sudo lsof -p $(pidof gotop) . It shows all files opened by the process. And then post the output here.

I pushed a possible fix to ataattr branch. Please try the branch and let me know if you see any improvement with the file descriptor leak.

commented

I encountered this problem when I was using github.com/anatol/smart.go v0.0.0-20220404164659-a19872369963 as seen in this PR: xxxserxxx/gotop#221

To reproduce this issue it's necessary to run gotop in a machine with at least a SATA disk. Instructions here (https://github.com/xxxserxxx/gotop)

My machine specs:
Fedora Silverblue 36.20220613.0
Linux kernel v5.17.13-300.fc36.x86_64
go version go1.18.2 linux/amd64
2 SATA SSDs
2 HDDs

I've executed gotop with the following arguments:
sudo gotop --layout disk --rate 10s --color nord --

here's the output of sudo strace -f gotop:
strace.txt

output of sudo lsof -p $(pidof gotop):
lsof.txt

I've tried to reproduce the issue with the atattr branch and haven't managed to get the error so far. I'll try again tomorrow.

I ran a simple test with code similar to what you have in gotop and I do not see any fd leaks. Try my latest changes and let me know if you have any problems.

@rare-magma how did the fix work? Do you still see the fd leak?

commented

@anatol I tried to reproduce again with your latest changes and wasn't successful so I believe the issue is solved.
Thanks!