-
-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Too many connections opened on OS #47
Comments
找到出异常位置 2019/12/21 14:21:40 Polling wakenUpserver is going to be shutdown |
其实这个不是 bug,而是正常的关闭 gnet 的时候close 了两次 fd,所以第二次的时候会提示已经 close 过了,因为不是什么大问题,以前一直没处理这个重复关闭的问题,等会儿我把重复关闭的地方修复下吧 |
问题是我没让他关闭,他自己关闭了,不知道是因为什么原因关闭 |
什么意思?server 自己 shutdown 了?有没有 panic 什么的? |
找到了,又是文件描述符之前的问题。。。。。 |
Accept 的时候返回 |
是的,然后ACCEPT退出,然后SVR.STOP关闭所有连接退出。。。因为关闭连接打了日志,关闭的时候太多日志看不见上面的日志 |
不知道有没办法突破WIN限制,每次10000,没几次,WIN客户端就connectex: Only one usage of each socket address (protocol/network address/port) is normally permitted.放DOCKER里测试电脑不够用 |
package main
import (
"fmt"
"net"
"time"
"golang.org/x/sys/unix"
)
func q(){
serverAddr := "192.168.2.201:9999"
tcpAddr, err := net.ResolveTCPAddr("tcp", serverAddr)
if err != nil {
fmt.Println("Resolve TCPAddr error", err)
}
conn, err := net.DialTCP("tcp4", nil, tcpAddr)
defer conn.Close()
time.Sleep(10*time.Millisecond)
}
func main() {
fmt.Println("aa")
lis,err :=net.Listen("tcp", "0.0.0.0:9999")
if err!=nil{
fmt.Println(err)
return
}
_ = lis
f,err:= lis.(*net.TCPListener).File()
if err!=nil{
fmt.Println(err)
return
}
fd := int(f.Fd())
//unix.SetNonblock(fd, true)
for{
nfd, sa, err := unix.Accept(fd)
if err != nil {
if err == unix.EAGAIN {
continue
}
fmt.Printf("asdasd%d %d\n",nfd,fd)
fmt.Println(err)
return
}
fmt.Printf("new %d\n",nfd)
_ = sa
unix.Close(nfd)
}
} 最近又试了一下,用上面这个服务器,客户端不断连接就bad file descriptor. ubuntu 18.04 go 1.13.6 1.13.8 |
你不用 |
我觉得我应该找到问题了 acceptFd, err := unix.Socket(unix.AF_INET, unix.SOCK_STREAM, 0)
if err != nil {
fmt.Println("Resolve TCPAddr error", err)
return
}
sockaddrInet4 := &unix.SockaddrInet4{
Port: 9999,
Addr: [4]byte{0, 0, 0, 0},
}
err = unix.Bind(acceptFd, sockaddrInet4)
if err != nil {
fmt.Println("1111111111", err)
return
}
err = unix.Listen(acceptFd, 100)
if err != nil {
fmt.Println("22222", err)
return
}
for {
clientFd, sa, err := unix.Accept(acceptFd)
if err != nil {
fmt.Println("333333333", err)
return
}
_ = sa
fmt.Printf("clientFd:%d\n", clientFd)
unix.Close(clientFd)
} 用原生LINUX调用就没有问题 go的lis Accept,会设置连接各种属性 |
你这个是哪部分的源码,我怎么找不到? |
gnet.go 227行 ln.ln, err = net.Listen(ln.network, ln.addr) 大批量连接就bad描述符。我改成原生API,就没问题。觉得是listener.accept做了其他处理,或者其他原因 |
我不是说 gnet 的源码,我说你贴的 go 的源码是哪里的,我没找到。 |
遇到同样的问题 换成@lonerwolf 的就好了 我设置了SetNonblock也没发现问题 |
Also enable SO_REUSEPORT to avoid Thundering Herd, besides, Fixes panjf2000#47 panjf2000#44 panjf2000#77
2019/12/21 14:21:41 close tcp:[::]:9761->: file already closed
2019/12/21 14:21:41 close tcp [::]:9761: use of closed network connection
2019/12/21 14:21:41
UBUNTU上开启服务,然后WIN上,不断建立连接发送关闭,服务端出现上面问题,不知道如何排查,在EPOLL里面打了很多日志,但是都没显示,是不是ACCEPT这里?
Describe the bug
A clear and concise description of what the bug is.
To Reproduce
Steps to reproduce the behavior:
Expected behavior
A clear and concise description of what you expected to happen.
Screenshots
If applicable, add screenshots to help explain your problem.
System Info (please complete the following information):
Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered: