panjf2000 / gnet

🚀 gnet is a high-performance, lightweight, non-blocking, event-driven networking framework written in pure Go.
https://gnet.host
Apache License 2.0
9.7k stars 1.04k forks source link

[Bug]: accept 接收到 unix.ECONNABORTED 错误时,main reactor is exiting 会退出 #453

Closed CloudGuan closed 1 year ago

CloudGuan commented 1 year ago

Actions I've taken before I'm here

What happened?

系统 Debain 10 gnet 版本 v1.6.4

应用在服务端监听时, accept 收到 unix.ECONNABORTED 错误会导致 gnet.Serve 退出,

func (svr *server) accept(fd int, _ netpoll.IOEvent) error {
    nfd, sa, err := unix.Accept(fd)
    if err != nil {
        if err == unix.EAGAIN  {
            return nil
        }
        svr.opts.Logger.Errorf("Accept() fails due to error: %v", err)
        return errors.ErrAcceptSocket
    }
    // ...... 
}

而 unix.ECONNABORTED 我看到在 /net/ipv4/af_inet.c 中

645         /* Connection was closed by RST, timeout, ICMP error
646          * or another process disconnected us.
647          */
648         if (sk->sk_state == TCP_CLOSE)
649                 goto sock_error; 

662 sock_error:
663         err = sock_error(sk) ? : -ECONNABORTED;
664         sock->state = SS_UNCONNECTED;
665         if (sk->sk_prot->disconnect(sk, flags))
666                 sock->state = SS_DISCONNECTING;
667         goto out;

在accpet调用前客户端立刻关闭连接,是否可以考虑忽略这个错误,继续accept

Major version of gnet

v1

Specific version of gnet

v1.6.4

Operating system

Linux

Relevant log output

2023-04-11T08:49:30.616454896+08:00     ERROR   gnet@v1.6.4/acceptor_unix.go:38 Accept() fails due to error: software caused connection abort
github.com/panjf2000/gnet.(*server).accept
        /usr/local/go/pkg/mod/github.com/panjf2000/gnet@v1.6.4/acceptor_unix.go:38
github.com/panjf2000/gnet.(*eventloop).activateMainReactor.func1
        /usr/local/go/pkg/mod/github.com/panjf2000/gnet@v1.6.4/reactor_default_linux.go:35
github.com/panjf2000/gnet/internal/netpoll.(*Poller).Polling
        /usr/local/go/pkg/mod/github.com/panjf2000/gnet@v1.6.4/internal/netpoll/epoll_default_poller.go:136
github.com/panjf2000/gnet.(*eventloop).activateMainReactor
        /usr/local/go/pkg/mod/github.com/panjf2000/gnet@v1.6.4/reactor_default_linux.go:35
github.com/panjf2000/gnet.(*server).activateReactors.func1
        /usr/local/go/pkg/mod/github.com/panjf2000/gnet@v1.6.4/server_unix.go:171
2023-04-11T08:49:30.61654129+08:00      ERROR   gnet@v1.6.4/reactor_default_linux.go:39 main reactor is exiting due to error: accept a new connection error
github.com/panjf2000/gnet.(*eventloop).activateMainReactor
        /usr/local/go/pkg/mod/github.com/panjf2000/gnet@v1.6.4/reactor_default_linux.go:39
github.com/panjf2000/gnet.(*server).activateReactors.func1
        /usr/local/go/pkg/mod/github.com/panjf2000/gnet@v1.6.4/server_unix.go:171

Code snippets (optional)

No response

How to Reproduce

Steps to reproduce the behavior:

  1. Go to '....'
  2. Click on '....'
  3. Do '....'
  4. See '....'

Does this issue reproduce with the latest release?

It can reproduce with the latest release