Golang program error panic: open config.json: too many open files

Problem: The program reports an error panic during operation

Report error:
Insert picture description here
Knowledge points:
too many open files (too many open files) is a common error in Linux systems. Files not only mean files, but also open communication links (such as sockets), ports being monitored, etc., so Sometimes it can also be called a handle. The cause is that the process has opened the number of files and communication links that exceed the system limit at a certain time.

Solution: The
first reaction is where the file handle is not released when the file handle is read. The troubleshooting code found that every open configuration file will defer file.Close() close after reading it.
Insert picture description here

  1. View the configuration of the system ulimit -a | grep open
  2. Check the open file limit of the program service, cat /proc/40636/limits, and find that the service limit does not inherit the system settings, but the system default 1024 limit. (The 40636 in the middle is the process number of the program)
  3. View the number of open files (connections) of the program service, lsof -p 40636 | wc -l (40636 is the process number of the program)
  4. Which links are opened by the program service lsof -p 40636> openfiles.log (40636 is the process number of the program)
  5. Later, I found that my program is managed by supervisorctl. The default minfds configuration of supervisorctl is 1024, which means the open file limit is 1024. After the modification, restart supervisorctl supervisorctl reload to solve the problem.

Retrieved from: https://www.jianshu.com/p/e3b2a7a8d8aa?utm_campaign=studygolang.com&utm_medium=studygolang.com&utm_source=studygolang.com

Guess you like

Origin blog.csdn.net/weixin_43202081/article/details/115347469
Recommended