Skip to content
This repository has been archived by the owner on Mar 29, 2024. It is now read-only.

Commit

Permalink
Add error message to connection when tunneling fails early
Browse files Browse the repository at this point in the history
  • Loading branch information
dhaavi committed Oct 6, 2023
1 parent 29fe5d8 commit 89292d9
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 14 deletions.
6 changes: 3 additions & 3 deletions crew/connect.go
Expand Up @@ -82,7 +82,7 @@ func (t *Tunnel) connectWorker(ctx context.Context) (err error) {
// TODO: Clean this up.
t.connInfo.Lock()
defer t.connInfo.Unlock()
t.connInfo.Failed(fmt.Sprintf("failed to establish route: %s", err), "")
t.connInfo.Failed(fmt.Sprintf("SPN failed to establish route: %s", err), "")
t.connInfo.Save()

tracer.Warningf("spn/crew: failed to establish route for %s: %s", t.connInfo, err)
Expand All @@ -97,11 +97,11 @@ func (t *Tunnel) connectWorker(ctx context.Context) (err error) {

t.connInfo.Lock()
defer t.connInfo.Unlock()
t.connInfo.Failed(tErr.Error(), "")
t.connInfo.Failed(fmt.Sprintf("SPN failed to initialize data tunnel (connect op): %s", tErr.Error()), "")
t.connInfo.Save()

// TODO: try with another route?
tracer.Warningf("spn/crew: failed to initialize tunnel for %s: %s", t.connInfo, err)
tracer.Warningf("spn/crew: failed to initialize data tunnel (connect op) for %s: %s", t.connInfo, err)
return tErr
}

Expand Down
52 changes: 41 additions & 11 deletions crew/op_connect.go
Expand Up @@ -529,18 +529,48 @@ func (op *ConnectOp) HandleStop(err *terminal.Error) (errorToSend *terminal.Erro
// Cancel workers.
op.cancelCtx()

// Avoid connecting to destination via this Hub if the was a connection
// error and no data was received.
if op.entry && // On clients only.
err.Is(terminal.ErrConnectionError) &&
op.outgoingTraffic.Load() == 0 {
// Only if no data was received (ie. sent to local application).
op.tunnel.avoidDestinationHub()
}
// Special client-side handling.
if op.entry {
// Mark the connection as failed if there was an error and no data was sent to the app yet.
if err.IsError() && op.outgoingTraffic.Load() == 0 {
// Set connection to failed and save it to propagate the update.
c := op.tunnel.connInfo
func() {
c.Lock()
defer c.Unlock()

if err.IsExternal() {
c.Failed(fmt.Sprintf(
"the exit node reported an error: %s", err,
), "")
} else {
c.Failed(fmt.Sprintf(
"connection failed locally: %s", err,
), "")
}

c.Save()
}()
}

// If we are on the client, don't leak local errors to the server.
if op.entry && !err.IsExternal() {
return terminal.ErrStopping
// Avoid connecting to the destination via this Hub if:
// - The error is external - ie. from the server.
// - The error is a connection error.
// - No data was received.
// This indicates that there is some network level issue that we can
// possibly work around by using another exit node.
if err.IsError() && err.IsExternal() &&
err.Is(terminal.ErrConnectionError) &&
op.outgoingTraffic.Load() == 0 {
op.tunnel.avoidDestinationHub()
}

// Don't leak local errors to the server.
if !err.IsExternal() {
// Change error that is reported.
return terminal.ErrStopping
}
}

return err
}

0 comments on commit 89292d9

Please sign in to comment.