Skip to content

Commit

Permalink
return an ErrNotSupported when lazy negotiation fails (#84)
Browse files Browse the repository at this point in the history
  • Loading branch information
marten-seemann authored Apr 21, 2022
1 parent 90f2bb1 commit cbe57f2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lazyClient.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ func (l *lazyClientConn) doReadHandshake() {
return
}

if tok == "na" {
l.rerr = ErrNotSupported
return
}
if tok != proto {
l.rerr = fmt.Errorf("protocol mismatch in lazy handshake ( %s != %s )", tok, proto)
return
Expand Down
20 changes: 20 additions & 0 deletions multistream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,26 @@ func TestProtocolNegotiationLazy(t *testing.T) {
verifyPipe(t, ac, b)
}

func TestProtocolNegotiationUnsupported(t *testing.T) {
a, b := newPipe(t)
mux := NewMultistreamMuxer()

done := make(chan struct{})
go func() {
defer close(done)
mux.Negotiate(a)
}()

c := NewMSSelect(b, "/foo")
c.Write([]byte("foo protocol data"))
_, err := c.Read([]byte{0})
if err != ErrNotSupported {
t.Fatalf("expected protocol /foo to be unsupported, got: %v", err)
}
c.Close()
<-done
}

func TestNegLazyStressRead(t *testing.T) {
const count = 75

Expand Down

0 comments on commit cbe57f2

Please sign in to comment.