Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix race condition in ErrProtocolNotSupported #138

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions internal/dispatcher/dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package dispatcher
import (
"context"
"crypto/rand"
"errors"
"fmt"
"sync"
"time"
Expand Down Expand Up @@ -110,13 +111,16 @@ func (d *Dispatcher) StartSessions(ctx context.Context, domains []universal.Doma
results <- d.StartSession(aggregateContext, dom)
}(domain)
}
var err error
for i := 0; i < len(domains); i++ {
err := <-results
if err != nil {
err = <-results
// The aggregateContext is canceled if one of the handshakes fails. We don't want to return
// the Canceled error if ErrProtocolNotSupported is present.
if !errors.Is(err, context.Canceled) {
return err
}
}
return nil
return err
}

func (d *Dispatcher) createHandler(key *receiverKey) *receiver {
Expand Down
2 changes: 1 addition & 1 deletion pkg/proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ func (p *Proxy) handleVehicleCommand(acct *account.Account, w http.ResponseWrite
}
defer car.Disconnect()

if err := car.StartSession(ctx, nil); err == protocol.ErrProtocolNotSupported {
if err := car.StartSession(ctx, nil); errors.Is(err, protocol.ErrProtocolNotSupported) {
p.markUnsupportedVIN(vin)
p.forwardRequest(acct.Host, w, req)
return err
Expand Down