Skip to content

Commit 60d9bbc

Browse files
committed
keep the entire packet alive (attached to GC root)
1 parent 6ef5d59 commit 60d9bbc

File tree

5 files changed

+38
-25
lines changed

5 files changed

+38
-25
lines changed

src/quic/quic.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ bool PreferredAddress::Resolve(
225225

226226
void Packet::MemoryInfo(MemoryTracker* tracker) const {
227227
tracker->TrackFieldWithSize("allocated", ptr_ != data_ ? len_ : 0);
228+
tracker->TrackField("retained", retained);
228229
}
229230

230231
Path::Path(

src/quic/quic.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,11 +398,16 @@ class Packet final : public MemoryRetainer {
398398
SET_MEMORY_INFO_NAME(Packet);
399399
SET_SELF_SIZE(Packet);
400400

401+
inline void AddRetained(BaseObjectPtr<BaseObject> retain){
402+
retained.push_back(retain);
403+
}
404+
401405
private:
402406
uint8_t data_[kDefaultMaxPacketLength];
403407
uint8_t* ptr_ = nullptr;
404408
size_t len_ = kDefaultMaxPacketLength;
405409
const char* diagnostic_label_ = nullptr;
410+
std::vector<BaseObjectPtr<BaseObject>> retained;
406411
};
407412

408413
// A utility class that wraps ngtcp2_path to adapt it to work with SocketAddress

src/quic/session.cc

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3241,20 +3241,21 @@ bool Session::Application::SendPendingData() {
32413241
return false;
32423242
}
32433243

3244-
// If stream_data.id is -1, then we're not serializing any data for any
3245-
// specific stream. We still need to process QUIC session packets tho.
3246-
if (stream_data.id > -1)
3247-
Debug(session(), "Serializing packets for stream id %" PRId64,
3248-
stream_data.id);
3249-
else
3250-
Debug(session(), "Serializing session packets");
3251-
32523244
// If the packet was sent previously, then packet will have been reset.
3253-
if (!packet) {
3245+
if (!pos) {
32543246
packet = CreateStreamDataPacket();
32553247
pos = packet->data();
32563248
}
32573249

3250+
// If stream_data.id is -1, then we're not serializing any data for any
3251+
// specific stream. We still need to process QUIC session packets tho.
3252+
if (stream_data.id > -1) {
3253+
Debug(session(), "Serializing packets for stream id %" PRId64,
3254+
stream_data.id);
3255+
packet->AddRetained(stream_data.stream->GetOutboundSource());
3256+
} else
3257+
Debug(session(), "Requesting serialized packet flush");
3258+
32583259
ssize_t nwrite = WriteVStream(&path, pos, &ndatalen, stream_data);
32593260
if (stream_data.id >= 0) {
32603261
Debug(session(),
@@ -3312,25 +3313,26 @@ bool Session::Application::SendPendingData() {
33123313
continue;
33133314
}
33143315

3315-
if(nwrite != 0){
3316+
if(nwrite != 0){ // -ve response i.e error
33163317
packet.reset();
33173318
session()->set_last_error(kQuicInternalError);
33183319
return false;
3319-
} else {
3320-
if (stream_data.id >= 0)
3321-
ResumeStream(stream_data.id);
3322-
3323-
// We are either congestion limited or done.
3324-
if (pos - packet->data()) {
3325-
// Some data was serialized into the packet. We need to send it.
3326-
packet->set_length(pos - packet->data());
3327-
Debug(session(), "Congestion limited, but %" PRIu64 " bytes pending",
3328-
packet->length());
3329-
if (!session()->SendPacket(std::move(packet), path))
3330-
return false;
3331-
}
3332-
return true;
33333320
}
3321+
3322+
// 0 bytes in this sending operation
3323+
if (stream_data.id >= 0)
3324+
ResumeStream(stream_data.id);
3325+
3326+
// We are either congestion limited or done.
3327+
if (pos - packet->data()) {
3328+
// Some data was serialized into the packet. We need to send it.
3329+
packet->set_length(pos - packet->data());
3330+
Debug(session(), "Congestion limited, but %" PRIu64 " bytes pending",
3331+
packet->length());
3332+
if (!session()->SendPacket(std::move(packet), path))
3333+
return false;
3334+
}
3335+
return true;
33343336
}
33353337

33363338
pos += nwrite;
@@ -3346,7 +3348,6 @@ bool Session::Application::SendPendingData() {
33463348
Debug(session(), "-- Failed to send packet");
33473349
return false;
33483350
}
3349-
packet.reset();
33503351
pos = nullptr;
33513352
if (++packets_sent == kMaxPackets) {
33523353
Debug(session(), "-- Max packets sent");

src/quic/stream.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,10 @@ void Stream::Commit(size_t amount) {
336336
CHECK_LE(actual, amount);
337337
}
338338

339+
BaseObjectPtr<BaseObject> Stream::GetOutboundSource() const {
340+
return outbound_source_strong_ptr_;
341+
}
342+
339343
int Stream::DoPull(
340344
bob::Next<ngtcp2_vec> next,
341345
int options,

src/quic/stream.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,8 @@ class Stream final : public AsyncWrap,
187187
// Attaches an outbound Buffer::Source
188188
void AttachOutboundSource(Buffer::Source* source);
189189

190+
BaseObjectPtr<BaseObject> GetOutboundSource() const;
191+
190192
// Signals the beginning of a new block of headers.
191193
void BeginHeaders(HeadersKind kind);
192194

0 commit comments

Comments
 (0)