Skip to content
This repository has been archived by the owner on Jul 8, 2020. It is now read-only.

Close the connection on the server when the client closes it first #8

Merged
merged 1 commit into from
Jul 9, 2016
Merged

Close the connection on the server when the client closes it first #8

merged 1 commit into from
Jul 9, 2016

Conversation

folbricht
Copy link
Contributor

When the client closes the connection, the server will read EOF. In that case the connection should be closed on the server as well. Without this change the server goroutine will go into an infinite loop when the client closes the connection. It'll try to read, get an EOF, then "continue", go back to read, get another EOF and so on. That takes 100% CPU in this situation.

When the client closes the connection, the server will read EOF. In that case the connection should be closed on the server as well. Without this change the server goroutine will go into an infinite loop when the client closes the connection. It'll try to read, get an EOF, then "continue", go back to read, get another EOF and so on. That takes 100% CPU in this situation.
@@ -69,7 +69,7 @@ func (conn *Conn) Serve() {
line, err := conn.controlReader.ReadString('\n')
if err != nil {
if err == io.EOF {
continue
break
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should log if the error is different than io.EOF and let it break otherwise as it's the default. More DRY.

@lunny lunny merged commit bb49d51 into goftp:master Jul 9, 2016
@lunny
Copy link
Member

lunny commented Jul 9, 2016

Thanks!

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

Successfully merging this pull request may close these issues.

None yet

3 participants