TUN-5118: Quic connection now detects duplicate connections similar to http2

This commit is contained in:
Sudarsan Reddy
2021-09-21 07:11:36 +01:00
parent e2b18364f4
commit fd14bf440b
3 changed files with 124 additions and 84 deletions

View File

@@ -57,7 +57,11 @@ func NewQUICConnection(
return nil, errors.Wrap(err, "failed to open a registration stream")
}
go controlStreamHandler.ServeControlStream(ctx, registrationStream, connOptions)
err = controlStreamHandler.ServeControlStream(ctx, registrationStream, connOptions)
if err != nil {
// Not wrapping error here to be consistent with the http2 message.
return nil, err
}
return &QUICConnection{
session: session,
@@ -74,6 +78,10 @@ func (q *QUICConnection) Serve(ctx context.Context) error {
for {
stream, err := q.session.AcceptStream(ctx)
if err != nil {
// context.Canceled is usually a user ctrl+c. We don't want to log an error here as it's intentional.
if errors.Is(err, context.Canceled) {
return nil
}
return errors.Wrap(err, "failed to accept QUIC stream")
}
go func() {

View File

@@ -16,7 +16,6 @@ import (
"os"
"sync"
"testing"
"time"
"github.com/gobwas/ws/wsutil"
"github.com/lucas-clemente/quic-go"
@@ -27,6 +26,7 @@ import (
quicpogs "github.com/cloudflare/cloudflared/quic"
"github.com/cloudflare/cloudflared/tunnelrpc/pogs"
tunnelpogs "github.com/cloudflare/cloudflared/tunnelrpc/pogs"
)
// TestQUICServer tests if a quic server accepts and responds to a quic client with the acceptance protocol.
@@ -158,21 +158,7 @@ func TestQUICServer(t *testing.T) {
)
}()
rpcClientFactory := mockRPCClientFactory{
registered: make(chan struct{}),
unregistered: make(chan struct{}),
}
obs := NewObserver(&log, &log, false)
controlStream := NewControlStream(
obs,
mockConnectedFuse{},
&NamedTunnelConfig{},
1,
rpcClientFactory.newMockRPCClient,
nil,
1*time.Second,
)
controlStream := fakeControlStream{}
qC, err := NewQUICConnection(
ctx,
@@ -188,17 +174,20 @@ func TestQUICServer(t *testing.T) {
go qC.Serve(ctx)
wg.Wait()
select {
case <-rpcClientFactory.registered:
break //ok
case <-time.Tick(time.Second):
t.Fatal("timeout out waiting for registration")
}
cancel()
})
}
}
type fakeControlStream struct {
ControlStreamHandler
}
func (fakeControlStream) ServeControlStream(ctx context.Context, rw io.ReadWriteCloser, connOptions *tunnelpogs.ConnectionOptions) error {
return nil
}
func (fakeControlStream) IsStopped() bool {
return true
}
func quicServer(