proxy: fix handling of CloseRead/CloseWrite for TCP port proxy

Signed-off-by: Rolf Neugebauer <rolf.neugebauer@docker.com>
This commit is contained in:
Rolf Neugebauer 2016-06-10 16:05:14 +01:00
parent 7219b18964
commit a9fa07fd73

View File

@ -3,7 +3,6 @@ package libproxy
import ( import (
"io" "io"
"net" "net"
"syscall"
"github.com/Sirupsen/logrus" "github.com/Sirupsen/logrus"
) )
@ -47,13 +46,16 @@ func HandleTCPConnection(client Conn, backendAddr *net.TCPAddr, quit chan bool)
var broker = func(to, from Conn) { var broker = func(to, from Conn) {
written, err := io.Copy(to, from) written, err := io.Copy(to, from)
if err != nil { if err != nil {
// If the socket we are writing to is shutdown with logrus.Println("error copying:", err)
// SHUT_WR, forward it to the other end of the pipe: }
if err, ok := err.(*net.OpError); ok && err.Err == syscall.EPIPE { err = from.CloseRead()
from.CloseWrite() if err != nil {
} logrus.Println("error CloseRead from:", err)
}
err = to.CloseWrite()
if err != nil {
logrus.Println("error CloseWrite to:", err)
} }
to.CloseRead()
event <- written event <- written
} }