Skip to content

Commit e840784

Browse files
committed
TUN-6385: Don't share err between acceptStream loop and per-stream goroutines
1 parent 69b28e3 commit e840784

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

connection/quic.go

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,11 @@ func (q *QUICConnection) serveControlStream(ctx context.Context, controlStream q
122122
return nil
123123
}
124124

125+
// Close closes the session with no errors specified.
126+
func (q *QUICConnection) Close() {
127+
q.session.CloseWithError(0, "")
128+
}
129+
125130
func (q *QUICConnection) acceptStream(ctx context.Context) error {
126131
defer q.Close()
127132
for {
@@ -133,20 +138,17 @@ func (q *QUICConnection) acceptStream(ctx context.Context) error {
133138
}
134139
return fmt.Errorf("failed to accept QUIC stream: %w", err)
135140
}
136-
go func() {
137-
stream := quicpogs.NewSafeStreamCloser(quicStream)
138-
defer stream.Close()
139-
140-
if err = q.handleStream(stream); err != nil {
141-
q.logger.Err(err).Msg("Failed to handle QUIC stream")
142-
}
143-
}()
141+
go q.runStream(quicStream)
144142
}
145143
}
146144

147-
// Close closes the session with no errors specified.
148-
func (q *QUICConnection) Close() {
149-
q.session.CloseWithError(0, "")
145+
func (q *QUICConnection) runStream(quicStream quic.Stream) {
146+
stream := quicpogs.NewSafeStreamCloser(quicStream)
147+
defer stream.Close()
148+
149+
if err := q.handleStream(stream); err != nil {
150+
q.logger.Err(err).Msg("Failed to handle QUIC stream")
151+
}
150152
}
151153

152154
func (q *QUICConnection) handleStream(stream io.ReadWriteCloser) error {

0 commit comments

Comments
 (0)