Skip to content

Commit

Permalink
quic: fixup set_final_size
Browse files Browse the repository at this point in the history
Ignore subsequent calls to set_final_size unless the new size
is more than the previous, in which case, we have us a bug.

PR-URL: #34137
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: David Carlier <[email protected]>
  • Loading branch information
jasnell committed Jul 1, 2020
1 parent d603418 commit def8e76
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/quic/node_quic_stream-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@ void QuicStream::set_flag(int32_t flag, bool on) {
}

void QuicStream::set_final_size(uint64_t final_size) {
CHECK_EQ(GetStat(&QuicStreamStats::final_size), 0);
// Only set the final size once.
if (is_flag_set(QUICSTREAM_FLAG_FIN)) {
CHECK_LE(final_size, GetStat(&QuicStreamStats::final_size));
return;
}
set_flag(QUICSTREAM_FLAG_FIN);
SetStat(&QuicStreamStats::final_size, final_size);
}

Expand Down
1 change: 0 additions & 1 deletion src/quic/node_quic_stream.cc
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,6 @@ void QuicStream::ReceiveData(
// When fin != 0, we've received that last chunk of data for this
// stream, indicating that the stream will no longer be readable.
if (flags & NGTCP2_STREAM_DATA_FLAG_FIN) {
set_flag(QUICSTREAM_FLAG_FIN);
set_final_size(offset + datalen);
EmitRead(UV_EOF);
}
Expand Down
6 changes: 5 additions & 1 deletion src/quic/node_quic_stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,11 @@ class QuicStream : public AsyncWrap,
// Specifies the kind of headers currently being processed.
inline void set_headers_kind(QuicStreamHeadersKind kind);

// Set the final size for the QuicStream
// Set the final size for the QuicStream. This only works
// the first time it is called. Subsequent calls will be
// ignored unless the subsequent size is greater than the
// prior set size, in which case we have a bug and we'll
// assert.
inline void set_final_size(uint64_t final_size);

// The final size is the maximum amount of data that has been
Expand Down

0 comments on commit def8e76

Please sign in to comment.