Skip to content
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

Double close of client connection upon when a client gracefully QUIT #489

Open
folays opened this issue Oct 14, 2024 · 0 comments
Open

Double close of client connection upon when a client gracefully QUIT #489

folays opened this issue Oct 14, 2024 · 0 comments

Comments

@folays
Copy link

folays commented Oct 14, 2024

Hello,

Tested with netcat client to the FTPd port, the client just does USER + PASS + QUIT, and I am polite on the client side (I keep the netcat connection opened after sending the QUIT command).

There is a double c.Conn.Close() On the ftpserverlib server when a client send a gracefully QUIT message :

  1. func (c *clientHandler) handleQUIT(_ string) error { in https://github.com/fclairamb/ftpserverlib/blob/v0.24.1/handle_misc.go#L298
    calls c.disconnect() which in func (c *clientHandler) disconnect() { at
    https://github.com/fclairamb/ftpserverlib/blob/v0.24.1/client_handler.go#L134
    does a FIRST (*clientHandler).conn.Close()

  2. then X nanoseconds later func (c *clientHandler) HandleCommands() { in
    https://github.com/fclairamb/ftpserverlib/blob/v0.24.1/client_handler.go#L401 has a :

func (c *clientHandler) HandleCommands() {
	defer c.end() // <----------------- here a problematic defer ?
        [...]
	for {
		if c.readCommand() {
			return
		}
	}

defer which calls c.conn.Close() a second time at
https://github.com/fclairamb/ftpserverlib/blob/v0.24.1/client_handler.go#L375

func (c *clientHandler) end() {
	c.server.driver.ClientDisconnected(c)
	c.server.clientDeparture(c)

	if err := c.conn.Close(); err != nil { // <------------- second close
		c.logger.Debug(
			"Problem closing control connection",
			"err", err,
		)
	}

SYMPTOM :

Here on a Linux, at least on a loopback TCP connection, superfluous messages appear in the logs :

Problem closing control connection | clientId="1" err="close tcp [::1]:21->[::1]:34446: use of closed network connection"

This is probably related to fclairamb/ftpserver#710

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant