netpoll
netpoll copied to clipboard
netpoll should handle error with backoff
Describe the bug
netpoll should handle error with backoff
To Reproduce
mkdir hello
cd hello
go mod init hello
curl -L -O https://github.com/cloudwego/hertz-examples/raw/main/hello/main.go
go mod tidy
go build .
ulimit -n 10
./hello
Open another terminal and telnet several times.
telnet 127.0.0.1 8888 &
telnet 127.0.0.1 8888 &
Now there are tons of logs. It may be 10MB per second.
2023/01/13 04:16:02 accept conn failed: too many open files
2023/01/13 04:16:02 accept conn failed: too many open files
......
Expected behavior
Don't print so many logs.
Screenshots
netpoll server
go net http server

Server:
- OS: Ubuntu 20.04 Linux 5.4.0-47-generic
- go: 1.19.5
- hertz: v0.5.0
- netpoll: v0.3.1
Additional context
netpoll server implement
https://github.com/cloudwego/netpoll/blob/6a5a4f7cb79118e1152c469c1b0ac216049a28c2/netpoll_server.go#L96-L103
go net http server implement
https://github.com/golang/go/blob/245e95dfabd77f337373bf2d6bb47cd353ad8d74/src/net/http/server.go#L3064-L3076
I think the true problem is that your dont have enough max_open_files.
try to use ulimit -n 1024000 on your linux os and try again.
ulimit is a way that system provided to prevent a process from using too many resources. accept syscall returns EMFILE or ENFILE when it reaches the limit. The limit could be very large (eg. 1024000) or be the default 65535, and it may also be limit to 1024 by the system admin on purpose. Maybe some other code exactly needs to open many files to search for some thing. So less file descriptors for web service.
go net http server handled it. It won't cry for giving it larger fd limit. It just wait once per second for other connection closed.
go net http server handled it. It won't cry for giving it larger fd limit.
It's a interesting suggestion, will reconsider it. thanks!
@ganlvtech https://github.com/cloudwego/netpoll/pull/311 already find a way to fix it