Skip to content
This repository has been archived by the owner on Mar 22, 2019. It is now read-only.

After restarted, Listener.Close() doesn't lead Listener.Accept() to return #40

Open
wllenyj opened this issue Aug 20, 2018 · 0 comments

Comments

@wllenyj
Copy link

wllenyj commented Aug 20, 2018

At the StartProcess function, while Listener' s File() is called, this will puts the Listener fd into blocking mode. This should lead to Accept() can't return even if Listener.Close() is called.
Listener File() --> (fd *netFD) dup()

func (fd *netFD) dup() (f *os.File, err error) {
    ns, err := dupCloseOnExec(fd.pfd.Sysfd)
    if err != nil {
        return nil, err 
    }   

    // We want blocking mode for the new fd, hence the double negative.
    // This also puts the old fd into blocking mode, meaning that
    // I/O will block the thread instead of letting us use the epoll server.
    // Everything will still work, just with more threads.
    if err = fd.pfd.SetBlocking(); err != nil {
        return nil, os.NewSyscallError("setnonblock", err)
    }   

    return os.NewFile(uintptr(ns), fd.name()), nil 
}

So, User either use Shutdown to close socket, or use syscall.SetNonblock to put the Listener fd into the nonblock.

@wllenyj wllenyj changed the title After restarted, Listener.Accept() will not return even if Listener.Close() is called After restarted, Listener.Close() doesn't lead Listener.Accept() to return Aug 20, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant