bryancall commented on code in PR #14001:
URL: https://github.com/apache/trafficserver/pull/14001#discussion_r4489171099
##########
src/proxy/http3/Http3HeaderVIOAdaptor.cc:
##########
@@ -45,6 +45,11 @@ Http3HeaderVIOAdaptor::Http3HeaderVIOAdaptor(VIO *sink,
HTTPType http_type, QPAC
Http3HeaderVIOAdaptor::~Http3HeaderVIOAdaptor()
{
+ // QPACK may still hold this adaptor and its header, for a decode that is
+ // blocked or whose result is still in the event queue.
+ if (this->_qpack != nullptr) {
Review Comment:
Fixed in
[d68912c522](https://github.com/apache/trafficserver/pull/14001/commits/d68912c522a88be7c2c54a9a9b90e6240d38ab02)
and
[00f64ead84](https://github.com/apache/trafficserver/pull/14001/commits/00f64ead8487d828eb231ff25837aa7dc85bf1b8).
The check is in `cancel()` rather than here, so it covers every caller: QPACK
remembers the thread its first `decode()` ran on, and `cancel()`
release-asserts it runs there
([QPACK.cc](https://github.com/apache/trafficserver/blob/00f64ead8487d828eb231ff25837aa7dc85bf1b8/src/proxy/http3/QPACK.cc#L329-L330)).
It holds for this destructor. The adaptor is a member of `Http3Transaction`,
which is tied to the thread that created it
([Http3Transaction.cc](https://github.com/apache/trafficserver/blob/00f64ead8487d828eb231ff25837aa7dc85bf1b8/src/proxy/http3/Http3Transaction.cc#L71)),
and `decode()` is only reached from `_process_read_vio()`, which
release-asserts that thread
([Http3Transaction.cc](https://github.com/apache/trafficserver/blob/00f64ead84
87d828eb231ff25837aa7dc85bf1b8/src/proxy/http3/Http3Transaction.cc#L710)).
Session teardown deletes the transactions on the connection's thread before it
deletes the QPACK objects
([Http3Session.cc](https://github.com/apache/trafficserver/blob/00f64ead8487d828eb231ff25837aa7dc85bf1b8/src/proxy/http3/Http3Session.cc#L213-L219)).
##########
src/proxy/http3/QPACK.cc:
##########
@@ -310,6 +319,68 @@ QPACK::decode(uint64_t stream_id, const uint8_t
*header_block, size_t header_blo
return 0;
}
+int
+QPACK::cancel(uint64_t stream_id)
+{
+ int dropped = 0;
+
+ for (DecodeReport *r = this->_pending_reports.head(); r != nullptr;) {
+ DecodeReport *next = DecodeReport::Linkage::next_ptr(r);
+ if (r->stream_id() == stream_id) {
+ // The report is still in the event queue and frees itself when it runs.
+ this->_pending_reports.erase(r);
+ r->withdraw();
+ ++dropped;
+ }
+ r = next;
+ }
+
+ for (DecodeRequest *r = this->_blocked_list.head(); r != nullptr;) {
+ DecodeRequest *next = DecodeRequest::Linkage::next_ptr(r);
+ if (r->stream_id() == stream_id) {
+ this->_blocked_list.erase(r);
+ delete r;
+ ++dropped;
+ }
+ r = next;
+ }
+
+ return dropped;
+}
Review Comment:
Fixed in
[d68912c522](https://github.com/apache/trafficserver/pull/14001/commits/d68912c522a88be7c2c54a9a9b90e6240d38ab02)
and
[00f64ead84](https://github.com/apache/trafficserver/pull/14001/commits/00f64ead8487d828eb231ff25837aa7dc85bf1b8).
QPACK records the thread of its first `decode()`, and both `decode()` and
`cancel()` release-assert they run on it
([decode](https://github.com/apache/trafficserver/blob/00f64ead8487d828eb231ff25837aa7dc85bf1b8/src/proxy/http3/QPACK.cc#L290-L294),
[cancel](https://github.com/apache/trafficserver/blob/00f64ead8487d828eb231ff25837aa7dc85bf1b8/src/proxy/http3/QPACK.cc#L329-L330)).
I made it a release assert to match how the HTTP/3 transactions check their
own thread.
##########
include/proxy/http3/QPACK.h:
##########
@@ -65,13 +65,25 @@ class QPACK : public QUICApplication
int encode(uint64_t stream_id, HTTPHdr &header_set, MIOBuffer *header_block,
uint64_t &header_block_len);
/*
- * This will emit either of two events below:
- * - QPACK_EVENT_DECODE_COMPLETE (Data: *HTTPHdr)
- * - QPACK_EVENT_DECODE_FAILED (Data: nullptr)
+ * This will emit either of two events below, on @a thread:
+ * - QPACK_EVENT_DECODE_COMPLETE (the event's cookie is &hdr)
+ * - QPACK_EVENT_DECODE_FAILED (the event's cookie is &hdr, or nullptr if the
+ * decoder had already failed)
+ *
+ * @a thread has to be the thread decode() is called on: QPACK keeps the
+ * results it has not delivered yet on a list that only that thread touches.
*/
int decode(uint64_t stream_id, const uint8_t *header_block, size_t
header_block_len, HTTPHdr &hdr, Continuation *cont,
EThread *thread = this_ethread());
Review Comment:
Fixed in
[d68912c522](https://github.com/apache/trafficserver/pull/14001/commits/d68912c522a88be7c2c54a9a9b90e6240d38ab02).
`decode()` no longer takes a thread
([QPACK.h](https://github.com/apache/trafficserver/blob/00f64ead8487d828eb231ff25837aa7dc85bf1b8/include/proxy/http3/QPACK.h#L78)).
Its only caller already used the default, so it uses `this_ethread()` directly.
##########
src/proxy/http3/QPACK.cc:
##########
@@ -310,6 +319,68 @@ QPACK::decode(uint64_t stream_id, const uint8_t
*header_block, size_t header_blo
return 0;
}
+int
+QPACK::cancel(uint64_t stream_id)
+{
+ int dropped = 0;
+
+ for (DecodeReport *r = this->_pending_reports.head(); r != nullptr;) {
+ DecodeReport *next = DecodeReport::Linkage::next_ptr(r);
+ if (r->stream_id() == stream_id) {
+ // The report is still in the event queue and frees itself when it runs.
+ this->_pending_reports.erase(r);
+ r->withdraw();
+ ++dropped;
+ }
+ r = next;
+ }
+
+ for (DecodeRequest *r = this->_blocked_list.head(); r != nullptr;) {
+ DecodeRequest *next = DecodeRequest::Linkage::next_ptr(r);
+ if (r->stream_id() == stream_id) {
+ this->_blocked_list.erase(r);
+ delete r;
+ ++dropped;
+ }
+ r = next;
+ }
+
+ return dropped;
+}
+
+QPACK::DecodeReport::DecodeReport(QPACK *qpack, Continuation *continuation,
uint64_t stream_id, int event, HTTPHdr *hdr)
+ : Continuation(continuation->mutex), _qpack(qpack),
_continuation(continuation), _stream_id(stream_id), _event(event), _hdr(hdr)
+{
+ SET_HANDLER(&QPACK::DecodeReport::deliver);
+}
+
+int
+QPACK::DecodeReport::deliver(int /* event ATS_UNUSED */, Event *data)
+{
+ // Off the list before the handler runs: the handler may destroy its owner,
+ // which cancels this stream, or the session that owns this QPACK.
+ if (this->_qpack != nullptr) {
+ this->_qpack->_pending_reports.erase(this);
+ }
+ if (this->_continuation != nullptr) {
+ data->cookie = this->_hdr;
+ this->_continuation->handleEvent(this->_event, data);
+ }
+ delete this;
+ return EVENT_DONE;
+}
Review Comment:
I'm leaving this one as is. The `Event` only carries the cookie: the one
consumer, `Http3HeaderVIOAdaptor::event_handler`, never reads it
([Http3HeaderVIOAdaptor.cc](https://github.com/apache/trafficserver/blob/00f64ead8487d828eb231ff25837aa7dc85bf1b8/src/proxy/http3/Http3HeaderVIOAdaptor.cc#L92)),
and nothing cancels it or compares it to a stored event. Scheduling a separate
event for the consumer would add another trip through the event queue, which
`cancel()` would then also have to withdraw.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]