You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Robin Stevens <Ro...@xyzt.ai> on 2023/03/14 09:00:40 UTC

HTTP2: How to check if the client aborted a request

Version: Tomcat 9.0.35 (embedded in Spring Boot 2.3.0.RELEASE)

Use case / problem:

The frontend is doing requests that trigger heavy calculations in the backend. Often these requests get cancelled by the frontend before the backend has finished doing the calculations.

The cancellation of the requests is done by using an AbortController (https://developer.mozilla.org/en-US/docs/Web/API/AbortController) to abort the fetch (similar to this example https://developer.mozilla.org/en-US/docs/Web/API/AbortController/abort#examples).

When aborting a fetch that happens over HTTP2, an RST_FRAME is send to the server.

I'm trying to figure out how to detect in the backend that such an RST_FRAME has been received, and stop doing my calculation.

This is done in a Spring Boot Application using the embedded Tomcat webserver, but I would already be glad if I can get a pointer on how to get this information in Tomcat through public apis. 
I'm hopeful I can figure out the integration with Spring myself.


Investigation:

What I already found is that the RST_FRAME is received in the backend, at which point the state in the org.apache.coyote.http2.StreamStateMachine switches to CLOSED_RST_TX. 
After that state switch, the org.apache.coyote.http2.StreamStateMachine#canWrite method returns false which I think is the information I need.
After all, if the result of my calculation cannot be written to the stream, there is no point in doing it.

The problem is that this information is hidden behind a bunch of package visible/protected classes and methods so I cannot access it without relying on reflection and implementation details.
And I couldn't find anything in the source code that exposes this information publicly. 
So I'm not even sure I'm on the right track here.

Does anybody has a pointer on how to obtain this info through official APIs, or to some documentation related to this that I might have missed ?

Thanks,

Robin

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: HTTP2: How to check if the client aborted a request

Posted by Mark Thomas <ma...@apache.org>.
On 14/03/2023 09:00, Robin Stevens wrote:

<snip/>

> Does anybody has a pointer on how to obtain this info through official APIs, or to some documentation related to this that I might have missed ?

The short answer is that there is no way do this via the Servlet API 
that doesn't involved trying to do I/O and then reacting to any error 
that is received.

This is an open issue for the Servlet spec. There have been a few 
discussions and proposals but no consensus so far. Servlet issue #433 is 
probably the best place to start reading up on what has been discussed 
so far:
https://github.com/jakartaee/servlet/issues/433

I currently think it is more likely than not that something to help with 
this will be introduced in the next iteration of the Servlet spec.

Mark

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: HTTP2: How to check if the client aborted a request

Posted by "EXT-Denton, Sam T" <sa...@boeing.com>.
I am also interested in this.  In my case, we added an "Abort Request" link to the placeholder page that is displayed while the calculation is on-going, but naturally nobody ever clicks on it.  :O  I am solidly In favor of anything that fixes this.

Sam Denton (he/him)
Advisor, Solutions Architect 
Mobile (314) 827-4017
24x7 SBS Suppot (405) 312-9936

Advanced Leave Notice: NONE

-----Original Message-----
From: Robin Stevens <Ro...@xyzt.ai> 
Sent: Tuesday, March 14, 2023 4:01 AM
To: users@tomcat.apache.org
Subject: HTTP2: How to check if the client aborted a request

Use case / problem:

The frontend is doing requests that trigger heavy calculations in the backend. Often these requests get cancelled by the frontend before the backend has finished doing the calculations.

The cancellation of the requests is done by using an AbortController (https://developer.mozilla.org/en-US/docs/Web/API/AbortController) to abort the fetch (similar to this example https://developer.mozilla.org/en-US/docs/Web/API/AbortController/abort#examples).

When aborting a fetch that happens over HTTP2, an RST_FRAME is send to the server.

I'm trying to figure out how to detect in the backend that such an RST_FRAME has been received, and stop doing my calculation.

This is done in a Spring Boot Application using the embedded Tomcat webserver, but I would already be glad if I can get a pointer on how to get this information in Tomcat through public apis. 
I'm hopeful I can figure out the integration with Spring myself.


Investigation:

What I already found is that the RST_FRAME is received in the backend, at which point the state in the org.apache.coyote.http2.StreamStateMachine switches to CLOSED_RST_TX. 
After that state switch, the org.apache.coyote.http2.StreamStateMachine#canWrite method returns false which I think is the information I need.
After all, if the result of my calculation cannot be written to the stream, there is no point in doing it.

The problem is that this information is hidden behind a bunch of package visible/protected classes and methods so I cannot access it without relying on reflection and implementation details.
And I couldn't find anything in the source code that exposes this information publicly. 
So I'm not even sure I'm on the right track here.

Does anybody has a pointer on how to obtain this info through official APIs, or to some documentation related to this that I might have missed ?

Thanks,

Robin


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org