envoy icon indicating copy to clipboard operation
envoy copied to clipboard

Handling response headers/trailers in ConnectionCallbacks::OnEvent(Remote/LocalClose) vs Dtor of network filter

Open IssaAbuKalbein opened this issue 1 year ago • 2 comments

Title: Handling response headers/trailers in ConnectionCallbacks::OnEvent(Remote/LocalClose) vs Dtor of network filter

Description: I'm trying to understand which operations happen between ConnectionCallbacks::OnEvent(ConnectionEvent::RemoteClose/LocalClose) and the destructor of network filters being called, I mean can I assume that the destruction of network filters is done immediately after OnEvent finish, or some operations happen in between, and if so which kind of operations can happen?

More context about my question: I'm using "TCP tunneling over HTTP" feature in TcpProxy filter with the following two options: propagate_response_headers & propagate_response_trailers and I want to read headers/trailers from FilterState at the end of the connection. Should I handle response headers/trailers in OnEvent callback (assuming they will not be received in any way after that) or should I wait in that to the destructor of network filter?

I've tried to understand what happens when envoy gets a reset from downstream -> ConnectionImpl::onFileEvent is called which includes a call for ConnectionCallbacks::OnEvent and adding items to deferred deletion list, then DispatcherImpl::deferredDelete is called which incluses destruction of network filters, but I'm not sure if in some situations can something happen between ConnectionImpl::onFileEvent and DispatcherImpl::deferredDelete?

image

IssaAbuKalbein avatar Feb 16 '24 22:02 IssaAbuKalbein

deferredDelete posts the delete to the event loop, so if the event loop is busy some other event processing could happen between the onEvent and Dtor.

lizan avatar Feb 22 '24 08:02 lizan

@lizan So handling response headers/trailers in onEvent can cause a loss of headers/trailers in some cases as they can be received after onEvent being called?

IssaAbuKalbein avatar Feb 23 '24 02:02 IssaAbuKalbein

This issue has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed in the next 7 days unless it is tagged "help wanted" or "no stalebot" or other activity occurs. Thank you for your contributions.

github-actions[bot] avatar Mar 24 '24 04:03 github-actions[bot]

This issue has been automatically closed because it has not had activity in the last 37 days. If this issue is still valid, please ping a maintainer and ask them to label it as "help wanted" or "no stalebot". Thank you for your contributions.

github-actions[bot] avatar Mar 31 '24 08:03 github-actions[bot]