Skip to content

Commit

Permalink
Don't return error if upstream doesn't respond
Browse files Browse the repository at this point in the history
  • Loading branch information
dviejokfs committed Apr 5, 2022
1 parent 0275ff8 commit 4b87ffc
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
4 changes: 2 additions & 2 deletions cmd/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ func (c serverCmd) run() error {
err = c.returnResponse(initialConn, messages.TunnelStatus_OK)
if err != nil {
mutex.Unlock()
_ = muxListener.Close()
delete(sessions, sni)
_ = muxListener.Close()
log.Trace().Msgf("failed to write message", conn.RemoteAddr().String())
err = c.returnResponse(initialConn, messages.TunnelStatus_ERROR)
if err != nil {
Expand All @@ -134,8 +134,8 @@ func (c serverCmd) run() error {
err = initialConn.Close()
if err != nil {
mutex.Unlock()
_ = muxListener.Close()
delete(sessions, sni)
_ = muxListener.Close()
log.Trace().Msgf("failed to close connection", conn.RemoteAddr().String())
err = c.returnResponse(initialConn, messages.TunnelStatus_ERROR)
if err != nil {
Expand Down
3 changes: 1 addition & 2 deletions pkg/tunnel/tunnel.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,14 @@ func (c tunnelClient) startSNIProxy(session *yamux.Session, remoteAddress string
destConn, err := net.DialTimeout("tcp", remoteAddress, time.Second*5)
if err != nil {
log.Trace().Msgf("Failed to connect to remote address: %v", err)
conn.Write([]byte("Failed to connect to remote address"))
connCloseErr := conn.Close()
if connCloseErr != nil {
log.Trace().Msgf("Failed to close connection: %v", connCloseErr)
}
if destConn != nil {
destConn.Close()
}
return err
continue
}
log.Debug().Msgf("client %s connected", conn.RemoteAddr().String())
copyConn := func(writer, reader net.Conn) {
Expand Down

0 comments on commit 4b87ffc

Please sign in to comment.