TUN-5600: Close QUIC transports as soon as possible while respecting graceful shutdown

This does a few fixes to make sure that the QUICConnection returns from
Serve when the context is cancelled.

QUIC transport now behaves like other transports: closes as soon as there
is no traffic, or at most by grace-period. Note that we do not wait for
UDP traffic since that's connectionless by design.
This commit is contained in:
Nuno Diegues
2022-01-04 19:00:44 +00:00
parent ead93e9f26
commit 628545d229
4 changed files with 33 additions and 17 deletions

View File

@@ -5,6 +5,7 @@ import (
"io"
"github.com/google/uuid"
"github.com/lucas-clemente/quic-go"
"github.com/rs/zerolog"
"golang.org/x/sync/errgroup"
)
@@ -50,7 +51,11 @@ func (m *manager) Serve(ctx context.Context) error {
for {
sessionID, payload, err := m.transport.ReceiveFrom()
if err != nil {
return err
if aerr, ok := err.(*quic.ApplicationError); ok && uint64(aerr.ErrorCode) == uint64(quic.NoError) {
return nil
} else {
return err
}
}
datagram := &newDatagram{
sessionID: sessionID,
@@ -69,7 +74,7 @@ func (m *manager) Serve(ctx context.Context) error {
for {
select {
case <-ctx.Done():
return ctx.Err()
return nil
case datagram := <-m.datagramChan:
m.sendToSession(datagram)
case registration := <-m.registrationChan: