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

Scoped services potential issue #2000

Open
gcoutable opened this issue May 26, 2023 · 0 comments
Open

Scoped services potential issue #2000

gcoutable opened this issue May 26, 2023 · 0 comments

Comments

@gcoutable
Copy link
Member

gcoutable commented May 26, 2023

Since #1912 we have started to use scoped services (Request scope in that case). During the review, it appeared that using such services outside the scope they are supposed to be, fails with:

org.springframework.beans.factory.support.ScopeNotActiveException: Error creating bean with name 'scopedTarget.feedbackMessageService': Scope 'request' is not active for the current thread; consider defining a scoped proxy for this bean if you intend to refer to it from a singleton
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:374) ~[spring-beans-6.0.8.jar:6.0.8]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200) ~[spring-beans-6.0.8.jar:6.0.8]
    at org.springframework.aop.target.SimpleBeanTargetSource.getTarget(SimpleBeanTargetSource.java:35) ~[spring-aop-6.0.8.jar:6.0.8]
    at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:686) ~[spring-aop-6.0.8.jar:6.0.8]
    at org.eclipse.sirius.components.web.services.FeedbackMessageService$$SpringCGLIB$$0.addFeedbackMessage(<generated>) ~[classes/:na]
    at org.eclipse.sirius.components.view.emf.diagram.ViewDiagramDescriptionConverter.lambda$33(ViewDiagramDescriptionConverter.java:364) ~[classes/:na]
    at org.eclipse.sirius.components.diagrams.components.NodeComponent.render(NodeComponent.java:96) ~[classes/:na]
    at org.eclipse.sirius.components.representations.BaseRenderer.renderComponent(BaseRenderer.java:200) ~[classes/:na]
...
Caused by: java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request.
    at org.springframework.web.context.request.RequestContextHolder.currentRequestAttributes(RequestContextHolder.java:131) ~[spring-web-6.0.8.jar:6.0.8]
    at org.springframework.web.context.request.AbstractRequestAttributesScope.get(AbstractRequestAttributesScope.java:42) ~[spring-web-6.0.8.jar:6.0.8]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:362) ~[spring-beans-6.0.8.jar:6.0.8]
    ... 69 common frames omitted

This stacktrace can be reproduced using the feedbackMessageService in the function returned by ViewDiagramDescriptionConverter#getSemanticElementsProvider and then, displaying a diagram.

A solution to prevent such stacktrace to be raised will be to check before the call of the service if it is in the scope it is supposed to be thanks to, a try-catch or, in a case of a request scope: if(RequestContextHolder.getRequestAttributes() != null){} or equivalent.

This issue is meant to trace a potential issue with scoped service.

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

No branches or pull requests

1 participant