Skip to content

Commit 7374d34

Browse files
committed
quic: don't block when closing read-only streams
Stream.Close blocks until all data sent on a stream has been acked by the peer. Don't block indefinitely when closing a read-only stream, waiting for an ack of data we never sent. For golang/go#58547 Change-Id: I4087666f739d7388e460b613d211c043626f1c87 Reviewed-on: https://go-review.googlesource.com/c/net/+/524038 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Jonathan Amsterdam <jba@google.com>
1 parent b4d09be commit 7374d34

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

internal/quic/stream.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ func newStream(c *Conn, id streamID) *Stream {
6666
inresetcode: -1, // -1 indicates no RESET_STREAM received
6767
ingate: newLockedGate(),
6868
outgate: newLockedGate(),
69-
outdone: make(chan struct{}),
69+
}
70+
if !s.IsReadOnly() {
71+
s.outdone = make(chan struct{})
7072
}
7173
return s
7274
}
@@ -237,6 +239,9 @@ func (s *Stream) Close() error {
237239
// CloseContext discards the buffer and returns the context error.
238240
func (s *Stream) CloseContext(ctx context.Context) error {
239241
s.CloseRead()
242+
if s.IsReadOnly() {
243+
return nil
244+
}
240245
s.CloseWrite()
241246
// TODO: Return code from peer's RESET_STREAM frame?
242247
return s.conn.waitOnDone(ctx, s.outdone)

internal/quic/stream_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -972,6 +972,17 @@ func TestStreamCloseWaitsForAcks(t *testing.T) {
972972
}
973973
}
974974

975+
func TestStreamCloseReadOnly(t *testing.T) {
976+
tc, s := newTestConnAndRemoteStream(t, serverSide, uniStream, permissiveTransportParameters)
977+
if err := s.CloseContext(canceledContext()); err != nil {
978+
t.Errorf("s.CloseContext() = %v, want nil", err)
979+
}
980+
tc.wantFrame("closed stream sends STOP_SENDING",
981+
packetType1RTT, debugFrameStopSending{
982+
id: s.id,
983+
})
984+
}
985+
975986
func TestStreamCloseUnblocked(t *testing.T) {
976987
for _, test := range []struct {
977988
name string

0 commit comments

Comments
 (0)