Golang ssh portforwarding:管道错误

I am trying to connect to two remote mongodb servers using ssh port-forwarding in golang which are used by my graphql server for querying. The intermediary host for the two tunnels is same. So let's say the intermediary host is 123.45.678.678 and the two remote mongodb servers are 1.23.45.67 and 1.23.45.78, I create the tunnels like this,

conn, err := ssh.Dial("tcp", 123.45.678.678, config)
if err != nil {
    panic(err)
}

remote1, err := conn.Dial("tcp", "1.23.45.67:27017")
if err != nil {
    panic(err)
}


remote2, err := conn.Dial("tcp", "1.23.45.78:27017")
if err != nil {
    panic(err)
}

local1, err := net.Listen("tcp", "localhost:27018")
if err != nil {
    panic(err)
}

local2, err := net.Listen("tcp", "localhost:27019")
if err != nil {
    panic(err)
}

Now i forward traffic from local1 to remote1 and local2 to remote2 like this

go func() {
    for {
        l, err := local1.Accept()
        if err != nil {
            panic(err)
        }
        go func() {
            _, err := io.Copy(l, remote1)
            if err != nil {
                panic(err)
            }
        }()
        go func() {
            _, err := io.Copy(remote1, l)
            if err != nil {
                panic(err)
            }
        }()
    }
}()
go func() {
    for {
        l, err := local2.Accept()
        if err != nil {
            panic(err)
        }
        go func() {
            _, err := io.Copy(l, remote2)
            if err != nil {
                panic(err)
            }
        }()
        go func() {
            _, err := io.Copy(remote2, l)
            if err != nil {
                panic(err)
            }
        }()
    }
}()

And I create two mongo sessions using mgo.Dial and export these two sessions to the graphql whenever this function is called. For some queries ( not all queries, only some complex queries ) which need both the sessions, i see the write: broken pipe error

 panic: readfrom tcp 127.0.0.1:27019->127.0.0.1:53128: write tcp 127.0.0.1:27019->127.0.0.1:53128: write: broken pipe

When I debugged this, i figured out that this error occurs when the io.copy happens between l and remote2 in the code snippet above which i guess is due to the disconnection of remote2 tunnel.

The tcpdump showed that the intermediary host is sending the finish flag to the remote2 server after sometime which inturn is leading to the termination of the connection. I am wondering how I can resolve this.