Skip to content

Commit

Permalink
Fix regression in session info
Browse files Browse the repository at this point in the history
Commit beb8735 introduced a
regression that prevents clients from establishing session info on
connections that are not cached. It caused a handshake to one domain to
be cancelled when a handshake to another domain succeeded.
  • Loading branch information
Seth Terashima authored and sethterashima committed Jan 19, 2024
1 parent d7a3e30 commit 7c9d6d8
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
2 changes: 1 addition & 1 deletion internal/dispatcher/dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func (d *Dispatcher) StartSessions(ctx context.Context, domains []universal.Doma
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) {
if err != nil && !errors.Is(err, context.Canceled) {
return err
}
}
Expand Down
37 changes: 36 additions & 1 deletion internal/dispatcher/dispatcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
)

var errOutboxFull = errors.New("dispatcher: outbox full")
var errDropMessage = errors.New("dispatcher: simulated dropped message")
var errTimeout = errors.New("dispatcher: simulated timeout")
var testPayload = []byte("ack")
var quiescentDelay = 250 * time.Millisecond
Expand Down Expand Up @@ -246,7 +247,11 @@ func (d *dummyConnector) Send(ctx context.Context, buffer []byte) error {
err := d.errorQueue[0]
d.errorQueue = d.errorQueue[1:]
d.lock.Unlock()
return err
if err == errDropMessage {
return nil
} else if err != nil {
return err
}
}
if err := proto.Unmarshal(buffer, &message); err != nil {
return err
Expand Down Expand Up @@ -646,6 +651,36 @@ func TestConnect(t *testing.T) {
}
}

func TestWaitForAllSessions(t *testing.T) {
conn := newDummyConnector(t)
defer conn.Close()

// Configure the Connector to only respond to the first of two handshakes
conn.EnqueueSendError(nil)
conn.EnqueueSendError(errDropMessage)

key, err := authentication.NewECDHPrivateKey(rand.Reader)
if err != nil {
t.Fatalf("Couldn't create private key: %s", err)
}

dispatcher, err := New(conn, key)
if err != nil {
t.Fatalf("Couldn't initialize dispatcher: %s", err)
}

ctx, cancel := context.WithTimeout(context.Background(), quiescentDelay)
defer cancel()

if err := dispatcher.Start(ctx); err != nil {
t.Fatal(err)
}

if err := dispatcher.StartSessions(ctx, nil); err != context.DeadlineExceeded {
t.Fatalf("Unexpected error: %s", err)
}
}

func TestRetrySend(t *testing.T) {
dispatcher, conn := getTestSetup(t)
defer conn.Close()
Expand Down

0 comments on commit 7c9d6d8

Please sign in to comment.