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

WebFlux pops scope before finishing transaction #2700

Closed
adinauer opened this issue May 5, 2023 Discussed in #2694 · 3 comments · Fixed by #2724
Closed

WebFlux pops scope before finishing transaction #2700

adinauer opened this issue May 5, 2023 Discussed in #2694 · 3 comments · Fixed by #2724
Assignees

Comments

@adinauer
Copy link
Member

adinauer commented May 5, 2023

Discussed in #2694

Tested on WebFlux with Spring Boot 2.7.5 on our sample.

The doFinally blocks of SentryWebFilter (should pop scope at the very end) and SentryWebTracingFilter (should finish the transaction before scope is popped) seem to run in reverse order.

@adinauer
Copy link
Member Author

adinauer commented May 5, 2023

This bug has been there since adding performance for WebFlux in 6.16.0. Spring Boot 3 is also affected.

@adinauer
Copy link
Member Author

adinauer commented May 10, 2023

We could use doOnTerminate instead of doFinally in SentryWebTracingFilter to ensure the transaction is finished before scope is popped.

An alternative could be to not pop the scope and rely on the hub being garbage collected as we now always clone a new hub from the main hub for every request.

@adinauer adinauer self-assigned this May 12, 2023
@adinauer
Copy link
Member Author

adinauer commented May 16, 2023

Things I tried but didn't work:

A

  • SentryWebFilter:
    • keep using doFinally
  • SentryWebTracingFilter:
    • use doOnTerminate

Didn't work out because doOnError in SentryWebTracingFilter is called after doOnTerminate.

B

  • SentryWebFilter:
    • keep using doFinally
  • SentryWebTracingFilter:
    • use doAfterTerminate

Didn't work out because doFinally in SentryWebFilter is called before doAfterTerminate in SentryWebTracingFilter.

C

  • SentryWebFilter:
    • use doAfterTerminate
  • SentryWebTracingFilter:
    • use doFinally

Didn't work out because doAfterTerminate in SentryWebFilter is called before doFinally in SentryWebTracingFilter.

D

  • SentryWebFilter:
    • use doAfterTerminate
  • SentryWebTracingFilter:
    • use doAfterTerminate

Didn't work because doAfterTerminate in SentryWebFilter is called before doAfterTerminate in SentryWebTracingFilter

Other things we could try

  • Not calling popScope
    • would hold on to memory until the thread is hit by another request
  • Merging SentryWebFilter and SentryWebTracingFilter into one filter bean with configurable behaviour.

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

Successfully merging a pull request may close this issue.

1 participant