bneradt commented on code in PR #9987: URL: https://github.com/apache/trafficserver/pull/9987#discussion_r1454097362
########## proxy/http2/Http2Stream.cc: ########## @@ -315,19 +309,36 @@ Http2Stream::send_request(Http2ConnectionState &cstate) } } while (!done); - if (bufindex == 0) { + if (dumpoffset == 0) { // No data to signal read event return; } // Is the _sm ready to process the header? if (this->read_vio.nbytes > 0) { if (this->receive_end_stream) { - this->read_vio.nbytes = bufindex; - this->read_vio.ndone = bufindex; + // This is dangerous. The _sm has possibly not read + // the data yet, so we end up with a mismatch if there + // is something async in between. + // Better would be to get the actual difference between + // the start of the headers and the actual position in + // the buffer for the ndone part. + // Howerver, during testing we have not seen any issues. + this->read_vio.nbytes = this->read_vio.ndone + dumpoffset; Review Comment: Yes. In fact, there are two separate `read_vio` instances: one for reading the response headers and one for reading the response body and trailers: ```gdb Thread 12 "[ET_NET 9]" hit Breakpoint 1, Http2Stream::do_io_read (this=0xffffc503efa0, c=0xffffc4fb7eb0, nbytes=9223372036854775807, buf=0xffffc503f168) at /home/bneradt/src/ts_asf_master_fix_grpc_memory_leak/src/proxy/http2/Http2Stream.cc:472 472 if (buf) { (gdb) bt #0 Http2Stream::do_io_read (this=0xffffc503efa0, c=0xffffc4fb7eb0, nbytes=9223372036854775807, buf=0xffffc503f168) at /home/bneradt/src/ts_asf_master_fix_grpc_memory_leak/src/proxy/http2/Http2Stream.cc:472 #1 0x0000000000920cc8 in HttpSM::setup_server_read_response_header (this=0xffffc4fb7eb0) at /home/bneradt/src/ts_asf_master_fix_grpc_memory_leak/src/proxy/http/HttpSM.cc:6627 #2 0x0000000000920980 in HttpSM::setup_server_send_request (this=0xffffc4fb7eb0) at /home/bneradt/src/ts_asf_master_fix_grpc_memory_leak/src/proxy/http/HttpSM.cc:6594 #3 0x000000000090b088 in HttpSM::handle_api_return (this=0xffffc4fb7eb0) at /home/bneradt/src/ts_asf_master_fix_grpc_memory_leak/src/proxy/http/HttpSM.cc:1559 #4 0x00000000009320c8 in HttpSM::do_api_callout (this=0xffffc4fb7eb0) at /home/bneradt/src/ts_asf_master_fix_grpc_memory_leak/src/proxy/http/HttpSM.cc:334 #5 0x000000000092052c in HttpSM::setup_server_send_request_api (this=0xffffc4fb7eb0) at /home/bneradt/src/ts_asf_master_fix_grpc_memory_leak/src/proxy/http/HttpSM.cc:6551 #6 0x000000000091e0d4 in HttpSM::handle_http_server_open (this=0xffffc4fb7eb0) at /home/bneradt/src/ts_asf_master_fix_grpc_memory_leak/src/proxy/http/HttpSM.cc:5957 #7 0x000000000090c168 in HttpSM::state_http_server_open (this=0xffffc4fb7eb0, event=1400, data=0xffffc4d898d0) at /home/bneradt/src/ts_asf_master_fix_grpc_memory_leak/src/proxy/http/HttpSM.cc:1780 #8 0x000000000090ffa0 in HttpSM::main_handler (this=0xffffc4fb7eb0, event=1400, data=0xffffc4d898d0) at /home/bneradt/src/ts_asf_master_fix_grpc_memory_leak/src/proxy/http/HttpSM.cc:2611 #9 0x000000000087a510 in Continuation::handleEvent (this=0xffffc4fb7eb0, event=1400, data=0xffffc4d898d0) at /home/bneradt/src/ts_asf_master_fix_grpc_memory_leak/include/iocore/eventsystem/Continuation.h:228 #10 0x0000000000983570 in ConnectingEntry::state_http_server_open (this=0xffffcc035070, event=102, data=0xffffc5b735e0) at /home/bneradt/src/ts_asf_master_fix_grpc_memory_leak/src/proxy/http/ConnectingEntry.cc:90 #11 0x000000000087a510 in Continuation::handleEvent (this=0xffffcc035070, event=102, data=0xffffc5b735e0) at /home/bneradt/src/ts_asf_master_fix_grpc_memory_leak/include/iocore/eventsystem/Continuation.h:228 #12 0x0000000000c38c54 in read_signal_and_update (event=102, vc=0xffffc5b73380) at /home/bneradt/src/ts_asf_master_fix_grpc_memory_leak/src/iocore/net/UnixNetVConnection.cc:87 #13 0x0000000000c39724 in read_signal_done (event=102, nh=0xfffff589eba0, vc=0xffffc5b73380) at /home/bneradt/src/ts_asf_master_fix_grpc_memory_leak/src/iocore/net/UnixNetVConnection.cc:154 #14 0x0000000000c3c744 in UnixNetVConnection::readSignalDone (this=0xffffc5b73380, event=102, nh=0xfffff589eba0) at /home/bneradt/src/ts_asf_master_fix_grpc_memory_leak/src/iocore/net/UnixNetVConnection.cc:969 #15 0x0000000000bec4d8 in SSLNetVConnection::net_read_io (this=0xffffc5b73380, nh=0xfffff589eba0, lthread=0xfffff589e010) at /home/bneradt/src/ts_asf_master_fix_grpc_memory_leak/src/iocore/net/SSLNetVConnection.cc:695 #16 0x0000000000c69938 in NetHandler::process_ready_list (this=0xfffff589eba0) at /home/bneradt/src/ts_asf_master_fix_grpc_memory_leak/src/iocore/net/NetHandler.cc:276 #17 0x0000000000c69d0c in NetHandler::waitForActivity (this=0xfffff589eba0, timeout=60000000) at /home/bneradt/src/ts_asf_master_fix_grpc_memory_leak/src/iocore/net/NetHandler.cc:364 #18 0x0000000000cab0f0 in EThread::execute_regular (this=0xfffff589e010) at /home/bneradt/src/ts_asf_master_fix_grpc_memory_leak/src/iocore/eventsystem/UnixEThread.cc:299 #19 0x0000000000cab294 in EThread::execute (this=0xfffff589e010) at /home/bneradt/src/ts_asf_master_fix_grpc_memory_leak/src/iocore/eventsystem/UnixEThread.cc:348 #20 0x0000000000ca9968 in spawn_thread_internal (a=0x11d0e90) at /home/bneradt/src/ts_asf_master_fix_grpc_memory_leak/src/iocore/eventsystem/Thread.cc:68 #21 0x0000fffff7020584 in start_thread (arg=0xfffff7fbcba0) at pthread_create.c:444 #22 0x0000fffff708fc4c [PAC] in thread_start () at ../sysdeps/unix/sysv/linux/aarch64/clone3.S:76 (gdb) finish Run till exit from #0 Http2Stream::do_io_read (this=0xffffc503efa0, c=0xffffc4fb7eb0, nbytes=9223372036854775807, buf=0xffffc503f168) at /home/bneradt/src/ts_asf_master_fix_grpc_memory_leak/src/proxy/http2/Http2Stream.cc:472 0x0000000000920cc8 in HttpSM::setup_server_read_response_header (this=0xffffc4fb7eb0) at /home/bneradt/src/ts_asf_master_fix_grpc_memory_leak/src/proxy/http/HttpSM.cc:6627 6627 server_entry->read_vio = server_txn->do_io_read(this, INT64_MAX, server_txn->get_remote_reader()->mbuf); Value returned is $4 = (VIO *) 0xffffc503f250 (gdb) c Continuing. ... Thread 12 "[ET_NET 9]" hit Breakpoint 1, Http2Stream::do_io_read (this=0xffffc503efa0, c=0xffffc4fb9808, nbytes=9223372036854775807, buf=0x12798f0) at /home/bneradt/src/ts_asf_master_fix_grpc_memory_leak/src/proxy/http2/Http2Stream.cc:472 472 if (buf) { (gdb) bt #0 Http2Stream::do_io_read (this=0xffffc503efa0, c=0xffffc4fb9808, nbytes=9223372036854775807, buf=0x12798f0) at /home/bneradt/src/ts_asf_master_fix_grpc_memory_leak/src/proxy/http2/Http2Stream.cc:472 #1 0x000000000097db50 in HttpTunnel::producer_run (this=0xffffc4fb9808, p=0xffffc4fb9bd8) at /home/bneradt/src/ts_asf_master_fix_grpc_memory_leak/src/proxy/http/HttpTunnel.cc:1021 #2 0x000000000097c4dc in HttpTunnel::tunnel_run (this=0xffffc4fb9808, p_arg=0xffffc4fb9bd8) at /home/bneradt/src/ts_asf_master_fix_grpc_memory_leak/src/proxy/http/HttpTunnel.cc:735 #3 0x000000000090b578 in HttpSM::handle_api_return (this=0xffffc4fb7eb0) at /home/bneradt/src/ts_asf_master_fix_grpc_memory_leak/src/proxy/http/HttpSM.cc:1624 #4 0x0000000000926a28 in HttpSM::set_next_state (this=0xffffc4fb7eb0) at /home/bneradt/src/ts_asf_master_fix_grpc_memory_leak/src/proxy/http/HttpSM.cc:7975 #5 0x0000000000925dfc in HttpSM::call_transact_and_set_next_state (this=0xffffc4fb7eb0, f=0x0) at /home/bneradt/src/ts_asf_master_fix_grpc_memory_leak/src/proxy/http/HttpSM.cc:7762 #6 0x000000000090b068 in HttpSM::handle_api_return (this=0xffffc4fb7eb0) at /home/bneradt/src/ts_asf_master_fix_grpc_memory_leak/src/proxy/http/HttpSM.cc:1552 #7 0x00000000009320c8 in HttpSM::do_api_callout (this=0xffffc4fb7eb0) at /home/bneradt/src/ts_asf_master_fix_grpc_memory_leak/src/proxy/http/HttpSM.cc:334 #8 0x000000000090d07c in HttpSM::state_read_server_response_header (this=0xffffc4fb7eb0, event=100, data=0xffffc503f250) at /home/bneradt/src/ts_asf_master_fix_grpc_memory_leak/src/proxy/http/HttpSM.cc:2017 #9 0x000000000090feac in HttpSM::main_handler (this=0xffffc4fb7eb0, event=100, data=0xffffc503f250) at /home/bneradt/src/ts_asf_master_fix_grpc_memory_leak/src/proxy/http/HttpSM.cc:2608 #10 0x000000000087a510 in Continuation::handleEvent (this=0xffffc4fb7eb0, event=100, data=0xffffc503f250) at /home/bneradt/src/ts_asf_master_fix_grpc_memory_leak/include/iocore/eventsystem/Continuation.h:228 #11 0x0000000000a13e38 in Http2Stream::signal_read_event (this=0xffffc503efa0, event=100) at /home/bneradt/src/ts_asf_master_fix_grpc_memory_leak/src/proxy/http2/Http2Stream.cc:878 #12 0x0000000000a10ac0 in Http2Stream::send_headers (this=0xffffc503efa0, cstate=...) at /home/bneradt/src/ts_asf_master_fix_grpc_memory_leak/src/proxy/http2/Http2Stream.cc:363 #13 0x00000000009f87f4 in Http2ConnectionState::rcv_headers_frame (this=0xffffc4d89c50, frame=...) at /home/bneradt/src/ts_asf_master_fix_grpc_memory_leak/src/proxy/http2/Http2ConnectionState.cc:487 #14 0x00000000009fdbe8 in Http2ConnectionState::rcv_frame (this=0xffffc4d89c50, frame=0xfffff498a7f8) at /home/bneradt/src/ts_asf_master_fix_grpc_memory_leak/src/proxy/http2/Http2ConnectionState.cc:1388 #15 0x00000000009f4588 in Http2CommonSession::do_complete_frame_read (this=0xffffc4d89c48) at /home/bneradt/src/ts_asf_master_fix_grpc_memory_leak/src/proxy/http2/Http2CommonSession.cc:324 #16 0x00000000009f4c8c in Http2CommonSession::do_process_frame_read (this=0xffffc4d89c48, event=100, vio=0xffffc5b735e0, inside_frame=false) at /home/bneradt/src/ts_asf_master_fix_grpc_memory_leak/src/proxy/http2/Http2CommonSession.cc:386 #17 0x00000000009f3a58 in Http2CommonSession::state_start_frame_read (this=0xffffc4d89c48, event=100, edata=0xffffc5b735e0) at /home/bneradt/src/ts_asf_master_fix_grpc_memory_leak/src/proxy/http2/Http2CommonSession.cc:237 #18 0x0000000000a1873c in Http2ServerSession::main_event_handler (this=0xffffc4d898d0, event=100, edata=0xffffc5b735e0) at /home/bneradt/src/ts_asf_master_fix_grpc_memory_leak/src/proxy/http2/Http2ServerSession.cc:175 #19 0x000000000087a510 in Continuation::handleEvent (this=0xffffc4d898d0, event=100, data=0xffffc5b735e0) at /home/bneradt/src/ts_asf_master_fix_grpc_memory_leak/include/iocore/eventsystem/Continuation.h:228 #20 0x0000000000c38c54 in read_signal_and_update (event=100, vc=0xffffc5b73380) at /home/bneradt/src/ts_asf_master_fix_grpc_memory_leak/src/iocore/net/UnixNetVConnection.cc:87 #21 0x0000000000c3c768 in UnixNetVConnection::readSignalAndUpdate (this=0xffffc5b73380, event=100) at /home/bneradt/src/ts_asf_master_fix_grpc_memory_leak/src/iocore/net/UnixNetVConnection.cc:975 #22 0x0000000000bec6a8 in SSLNetVConnection::net_read_io (this=0xffffc5b73380, nh=0xfffff589eba0, lthread=0xfffff589e010) at /home/bneradt/src/ts_asf_master_fix_grpc_memory_leak/src/iocore/net/SSLNetVConnection.cc:732 #23 0x0000000000c69938 in NetHandler::process_ready_list (this=0xfffff589eba0) at /home/bneradt/src/ts_asf_master_fix_grpc_memory_leak/src/iocore/net/NetHandler.cc:276 #24 0x0000000000c69d0c in NetHandler::waitForActivity (this=0xfffff589eba0, timeout=60000000) at /home/bneradt/src/ts_asf_master_fix_grpc_memory_leak/src/iocore/net/NetHandler.cc:364 #25 0x0000000000cab0f0 in EThread::execute_regular (this=0xfffff589e010) at /home/bneradt/src/ts_asf_master_fix_grpc_memory_leak/src/iocore/eventsystem/UnixEThread.cc:299 #26 0x0000000000cab294 in EThread::execute (this=0xfffff589e010) at /home/bneradt/src/ts_asf_master_fix_grpc_memory_leak/src/iocore/eventsystem/UnixEThread.cc:348 #27 0x0000000000ca9968 in spawn_thread_internal (a=0x11d0e90) at /home/bneradt/src/ts_asf_master_fix_grpc_memory_leak/src/iocore/eventsystem/Thread.cc:68 #28 0x0000fffff7020584 in start_thread (arg=0xfffff7fbcba0) at pthread_create.c:444 #29 0x0000fffff708fc4c [PAC] in thread_start () at ../sysdeps/unix/sysv/linux/aarch64/clone3.S:76 (gdb) finish Run till exit from #0 Http2Stream::do_io_read (this=0xffffc503efa0, c=0xffffc4fb9808, nbytes=9223372036854775807, buf=0x12798f0) at /home/bneradt/src/ts_asf_master_fix_grpc_memory_leak/src/proxy/http2/Http2Stream.cc:472 0x000000000097db50 in HttpTunnel::producer_run (this=0xffffc4fb9808, p=0xffffc4fb9bd8) at /home/bneradt/src/ts_asf_master_fix_grpc_memory_leak/src/proxy/http/HttpTunnel.cc:1021 1021 p->read_vio = p->vc->do_io_read(this, producer_n, p->read_buffer); Value returned is $5 = (VIO *) 0xffffc503f250 (gdb) c Continuing. ``` The same session shows an analogous set of reads for the client-side (one for headers, another for the body - although I confess my current test just has DATA frames and does not send trailing headers with the request). -- 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: github-unsubscr...@trafficserver.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org