Bug 3538 - Sshd reported error:Bind to port 22 failed because of Address already in use
Summary: Sshd reported error:Bind to port 22 failed because of Address already in use
Status: NEW
Alias: None
Product: Portable OpenSSH
Classification: Unclassified
Component: sshd (show other bugs)
Version: 9.1p1
Hardware: Other Linux
: P1 enhancement
Assignee: Assigned to nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-02-13 14:05 AEDT by renmingshuai
Modified: 2023-02-22 15:10 AEDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description renmingshuai 2023-02-13 14:05:03 AEDT
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?
Comment 1 Damien Miller 2023-02-22 15:10:21 AEDT
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.