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

[frontend-api] avoid session starting in FE API #2497

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

vitek-rostislav
Copy link
Contributor

@vitek-rostislav vitek-rostislav commented Jul 26, 2022

Q A
Description, reason for the PR FE API is stateless hence it does not use the session. The problem is the session is started for each GraphQL query anyway. In our code, the session is started even in the FE API for two reasons: 1) autowiring of FlashBagInterface Symfony service anywhere in the application -> the session is started during the build of the container (see symfony/symfony#36063); 2) CartMigrationFacade is defined as an event listener that listens on the kernel.controller event, therefore it is triggered even in the API requests. The facade was originally used in the Twig frontend only so it uses the session, but in the API requests, it does not work (and does not make any sense there). Besides the fact the session is useless in the API, it can be also dangerous as Redis can get overwhelmed by the huge number of pointless session entries.
New feature No
BC breaks Yes
Fixes issues ...
Have you read and signed our License Agreement for contributions? Yes

- FlashBagProvider is not wired in contructor anymore because it had side effects (session was started when the container was built)
	- see symfony/symfony#36063
- the current cart migration implementation does not work in the FE API so it is useless and dangerous to even try it (the session is started in the process which is unwanted in the API)
@sonarcloud
Copy link

sonarcloud bot commented Aug 17, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@vitek-rostislav
Copy link
Contributor Author

Hi @pk16011990, on a project, we encountered a very weird behavior - there was added a session entry in the Redis after doing a request on the storefront. The checker did not reveal this error because, at the time of its execution, the session was not started yet. This makes me think we should ensure the checker is called later than it is called now.

On the project, there was LogoutExceptionSubscriber service set as lazy. The subscriber was not called but I think that thanks to the lazy loading it was probably initialized after SessionChecker::onKernelResponse() was called so we could not be aware of the problem with the started session.

In this PR, the problem is resolved thanks to the usage of FlashBagProvider in LogoutExceptionSubscriber but I believe we should investigate the behavior described above and make the checker more reliable even in such edge-case scenarios.

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

Successfully merging this pull request may close these issues.

None yet

4 participants