When I run "systemctl restart sshd", the sshd service reported an error: Bind to port 22 failed because of Address already in use. Why the address is in use in this case is that the close() system call is asynchronous. The kernel implementation of close is to put the real close work in a work queue and wait for the system to schedule. When the system is busy, closing the socket may be delayed, and restarting the sshd service would cause this error. the call stack of close() is as shown below close(fd) // sshd calls close() SYSCALL_DEFINE1(close, unsigned int, fd); // kernel code __close_fd(current->files, fd); filp_close(filp,id); fput(filp); // put the next work in an work queue return retval; // return without confirming I don't know if it's a problem and if it is, how to solve it?
that really sounds like a bug in the kernel. The sequence of close+open should produce sensible results regardless of the kernel internals. I'd be surprised if sshd was the only thing affected by this.