Skip to content

proxy: fix an issue about half-closing net.TCPConn after io.Copy()#1598

Merged
sanimej merged 1 commit intomoby:masterfrom
AkihiroSuda:tcp-halfclose-docker-27539
Jan 6, 2017
Merged

proxy: fix an issue about half-closing net.TCPConn after io.Copy()#1598
sanimej merged 1 commit intomoby:masterfrom
AkihiroSuda:tcp-halfclose-docker-27539

Conversation

@AkihiroSuda
Copy link
Copy Markdown
Member

@AkihiroSuda AkihiroSuda commented Dec 22, 2016

Related to moby/moby#27539

After io.Copy(to, from), we should call to.CloseWrite(), not to.CloseRead().

Without this fix, TestTCP4ProxyHalfClose (newly added in this commit) fails as
follows:

--- FAIL: TestTCP4ProxyHalfClose (0.00s)
            network_proxy_test.go:135: EOF

In this test, the client calls Write(), CloseWrite(), then Read(), and the server calls ReadAll(), then Write().

Without the fix, the client fails to Read() because of EOF.

Signed-off-by: Akihiro Suda [email protected]

Comment thread cmd/proxy/tcp_proxy.go
from.CloseWrite()
}
}
to.CloseRead()
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@aboch
Copy link
Copy Markdown
Contributor

aboch commented Dec 22, 2016

Thanks @AkihiroSuda

LGTM

@aboch
Copy link
Copy Markdown
Contributor

aboch commented Dec 23, 2016

pls rebase

Fix moby/moby#27539

After io.Copy(to, from), we should call to.CloseWrite(), not to.CloseRead().

Without this fix, TestTCP4ProxyHalfClose (newly added in this commit) fails as
follows:

  --- FAIL: TestTCP4ProxyHalfClose (0.00s)
          network_proxy_test.go:135: EOF

Signed-off-by: Akihiro Suda <[email protected]>
@AkihiroSuda AkihiroSuda force-pushed the tcp-halfclose-docker-27539 branch from 14dac08 to d94f688 Compare December 24, 2016 20:49
@AkihiroSuda
Copy link
Copy Markdown
Member Author

done @aboch

@AkihiroSuda
Copy link
Copy Markdown
Member Author

Test failure seems unrelated

--- FAIL: TestLinkContainers (0.02s)
	bridge_test.go:722: Failed to setup driver config: unable to add return rule in DOCKER-ISOLATION chain:  (iptables failed: iptables --wait -I DOCKER-ISOLATION -j RETURN: iptables: No chain/target/match by that name.
		 (exit status 1))

Comment thread cmd/proxy/tcp_proxy.go
@@ -48,7 +48,8 @@ func (proxy *TCPProxy) clientLoop(client *net.TCPConn, quit chan bool) {
from.CloseWrite()
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This change looks good. Given that the half-close from either side is handled with the change do we still need this if block ? Also, from.CloseWrite() doesn't look correct here.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

 			if err, ok := err.(*net.OpError); ok && err.Err == syscall.EPIPE {
  				from.CloseWrite()
  			}

This looks unnecessary. But its not from this PR and can be addressed separately.

LGTM.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Uh, thank you for the comment and sorry for I did not respond.. 😅

I will try to remove that block after some verification

@sanimej sanimej merged commit f9fa6e0 into moby:master Jan 6, 2017
AkihiroSuda added a commit to AkihiroSuda/libnetwork that referenced this pull request Jan 12, 2017
sanimej pushed a commit that referenced this pull request Jan 20, 2017
proxy: clean up code (addendum to #1598)
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

Successfully merging this pull request may close these issues.

3 participants