Skip to content

Commit

Permalink
fix double close of chan when using DontCloseRequestStream (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
marten-seemann authored Sep 23, 2022
1 parent b0873bb commit 3c81ce5
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 3 deletions.
42 changes: 42 additions & 0 deletions client_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package webtransport_test

import (
"bytes"
"context"
"crypto/tls"
"errors"
"fmt"
"io"
"net"
Expand All @@ -14,6 +16,7 @@ import (

"github.com/lucas-clemente/quic-go"
"github.com/lucas-clemente/quic-go/http3"
"github.com/lucas-clemente/quic-go/quicvarint"

"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -45,6 +48,45 @@ func (c *requestStreamDelayingConn) OpenStreamSync(ctx context.Context) (quic.St
return str, nil
}

func TestClientInvalidResponseHandling(t *testing.T) {
tlsConf := tlsConf.Clone()
tlsConf.NextProtos = []string{"h3"}
s, err := quic.ListenAddr("localhost:0", tlsConf, nil)
require.NoError(t, err)
errChan := make(chan error)
go func() {
conn, err := s.Accept(context.Background())
require.NoError(t, err)
str, err := conn.AcceptStream(context.Background())
require.NoError(t, err)
// write a HTTP3 data frame. This will cause an error, since a HEADERS frame is expected
b := &bytes.Buffer{}
quicvarint.Write(b, 0x0)
quicvarint.Write(b, 1337)
_, err = str.Write(b.Bytes())
require.NoError(t, err)
for {
if _, err := str.Read(make([]byte, 64)); err != nil {
errChan <- err
return
}
}
}()

d := webtransport.Dialer{
RoundTripper: &http3.RoundTripper{
TLSClientConfig: &tls.Config{RootCAs: certPool},
},
}
_, _, err = d.Dial(context.Background(), fmt.Sprintf("https://localhost:%d", s.Addr().(*net.UDPAddr).Port), nil)
require.Error(t, err)
sErr := <-errChan
require.Error(t, sErr)
var appErr *quic.ApplicationError
require.True(t, errors.As(sErr, &appErr))
require.Equal(t, quic.ApplicationErrorCode(0x105), appErr.ErrorCode) // H3_FRAME_UNEXPECTED
}

func TestClientReorderedUpgrade(t *testing.T) {
timeout := scaleDuration(100 * time.Millisecond)
blockUpgrade := make(chan struct{})
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.18

require (
github.com/golang/mock v1.6.0
github.com/lucas-clemente/quic-go v0.29.0
github.com/lucas-clemente/quic-go v0.29.1
github.com/stretchr/testify v1.8.0
)

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/pty v1.1.3/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/lucas-clemente/quic-go v0.29.0 h1:Vw0mGTfmWqGzh4jx/kMymsIkFK6rErFVmg+t9RLrnZE=
github.com/lucas-clemente/quic-go v0.29.0/go.mod h1:CTcNfLYJS2UuRNB+zcNlgvkjBhxX6Hm3WUxxAQx2mgE=
github.com/lucas-clemente/quic-go v0.29.1 h1:Z+WMJ++qMLhvpFkRZA+jl3BTxUjm415YBmWanXB8zP0=
github.com/lucas-clemente/quic-go v0.29.1/go.mod h1:CTcNfLYJS2UuRNB+zcNlgvkjBhxX6Hm3WUxxAQx2mgE=
github.com/lunixbochs/vtclean v1.0.0/go.mod h1:pHhQNgMf3btfWnGBVipUOjRYhoOsdGqdm/+2c2E2WMI=
github.com/mailru/easyjson v0.0.0-20190312143242-1de009706dbe/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
github.com/marten-seemann/qpack v0.2.1 h1:jvTsT/HpCn2UZJdP+UUB53FfUUgeOyG5K1ns0OJOGVs=
Expand Down

0 comments on commit 3c81ce5

Please sign in to comment.