Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RequestEvent for RequestEventListener might lost request attributes for async flow #5695

Open
tutufool opened this issue Jul 9, 2024 · 5 comments

Comments

@tutufool
Copy link

tutufool commented Jul 9, 2024

Screenshot 2024-07-09 at 22 40 03

As you can see from above screen shot:

Thread A: request will be recycled ( attributes of request will be cleared)
Thread B: try to get request attribute from container request.

(Put breakpoints in 2 threads as above screenshot shows, let thread A go first to reproduce.)

And this is a simple spring boot application with parent: (could happen in older spring boot version)

		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>3.3.1</version>

Not sure if it's a known issue or expected behavior, please have a look.

And from the RequestEvent contract, it supposed to be able to get a stable ContainerRequest rather than a fragile one.
I guess maybe we had a chance to clone/copy the request context somewhere instead of relying underlying tomcat request object.

Thanks in advance!

@caiwei-ebay
Copy link

@jansupol @senivam Please share your insights.

@jansupol
Copy link
Contributor

Could you please share a reproducer?

@caiwei-ebay
Copy link

demoApp.zip

@jansupol Attached is the reproducer.

@jansupol
Copy link
Contributor

I was trying your reproducer, but I was unable to reproduce the exactly described behaviour outside of the spring boot environment.

What happens is that this is FINISHED event. So at first, Response.close() is called, all the data are wired on the network and after that the FINISHED event is called. By that time, it can be possible (depending on the server implementation) that the data from Request are no longer available, the attributes data are cleared.

The issue could be with the Spring injecting the HttpServletRequest, there could be a long way from that servlet to Jersey RequestEvent. Maybe instead of injecting HttpServletRequest by Spring and setting the request attribute, you can try to inject Jersey ContainerRequest and set the property there:

public void helloAsync(@Suspended AsyncResponse asyncResponse, @Context ContainerRequest request) {
   request.setProperty(name, value);
   ...
}

@tutufool
Copy link
Author

tutufool commented Aug 3, 2024

Same behavior after I tried ContainerRequest, they share same underlying org.apache.catalina.connector.Request. As long as the async thread calls the highlight line, I can't get attribute from ContainerRequest:

Screenshot 2024-08-03 at 16 56 29

@jansupol

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants