mirror of
https://github.com/cirruslabs/orchard.git
synced 2026-10-06 06:55:52 +02:00
* proxy.Connections(): handle "use of closed network connection" error * Controller: less strict timeouts that work nicely for WebSockets * Worker: only attempt connect to the gRPC once our UID is known * Introduce "orchard ssh" and "orchard vnc" commands * Worker: prevent context leak by moving logic into a separate function * Fix linter errors * Port forwarding integration test * Check for "uname -mo" output
48 lines
857 B
Go
48 lines
857 B
Go
package proxy
|
|
|
|
import (
|
|
"io"
|
|
"net"
|
|
"strings"
|
|
)
|
|
|
|
func Connections(left net.Conn, right net.Conn) (finalErr error) {
|
|
leftErrCh := make(chan error, 1)
|
|
rightErrCh := make(chan error, 1)
|
|
|
|
recordErr := func(newErr error) {
|
|
if newErr != nil && finalErr == nil {
|
|
finalErr = newErr
|
|
}
|
|
}
|
|
|
|
go func() {
|
|
_, err := io.Copy(left, right)
|
|
rightErrCh <- err
|
|
}()
|
|
|
|
go func() {
|
|
_, err := io.Copy(right, left)
|
|
leftErrCh <- err
|
|
}()
|
|
|
|
// Wait for some goroutine and then unlock the other goroutine
|
|
// by closing its source io.Reader
|
|
select {
|
|
case err := <-rightErrCh:
|
|
recordErr(err)
|
|
recordErr(left.Close())
|
|
recordErr(<-leftErrCh)
|
|
case err := <-leftErrCh:
|
|
recordErr(err)
|
|
recordErr(right.Close())
|
|
recordErr(<-rightErrCh)
|
|
}
|
|
|
|
if strings.Contains(finalErr.Error(), "use of closed network connection") {
|
|
finalErr = nil
|
|
}
|
|
|
|
return finalErr
|
|
}
|