sentry-symfony icon indicating copy to clipboard operation
sentry-symfony copied to clipboard

configureScope leaks when using FrankenPHP in worker mode

Open SherinBloemendaal opened this issue 10 months ago • 3 comments

How do you use Sentry?

Self-hosted / on-premises

SDK version

5.1.0

Steps to reproduce

Hi,

I've stumbled upon the some issues when running FrankenPHP in worker mode.(https://frankenphp.dev/docs/worker/).

First: The User PII is always the same:

  1. Run a Symfony application with FrankenPHP in worker mode
  2. Set send_default_pii: true in sentry.yaml
  3. Authenticate and trigger an exception
  4. Authenticate again with different user and trigger an exception
  5. The old PII (IP Address and User ID) is sent for the second exception

Second: Once a context is set using configureScope, the context stays in subsequent requests.

  1. Run a Symfony application with FrankenPHP in worker mode
  2. Call an endpoint (for example /test-1 via a controller), inside the controller add configureScope and set some context, then trigger an exception
  3. Call an another endpoint (for example /test-2 via a controller), inside the controller add configureScope and also set some context but set a different key (don't send the same key as the previous controller). Then trigger an exception again.
  4. Looking in Sentry; the second event contains a key of the previous call which was not set in the second call.

Expected result

The user PII should be refresh on each request and the entire configureScope should be reset properly by using the ResetInterface since it leaks when using FrankenPHP in worker mode (don't know if its intentional that it leaks).

About the PII it seems to be caused by: (...->getId() is only null on the first request) User: https://github.com/getsentry/sentry-symfony/blob/2f19c19dad002d5aa5025b9265dcf4f505909ec8/src/EventListener/LoginListener.php#L96 IP-address: https://github.com/getsentry/sentry-symfony/blob/2f19c19dad002d5aa5025b9265dcf4f505909ec8/src/EventListener/RequestListener.php#L58 The question is if the problem lies here or that the entire scope should be purged on each request.

Actual result

The context set inside the configureScope is never reset and leaking into different requests until FrankenPHP is restarted. Also causing the User PII to be always the same.

SherinBloemendaal avatar Jan 09 '25 09:01 SherinBloemendaal

We didn't optimize the Symfony SDK for asynchronous runtimes like FrankenPHP just yet.

cleptric avatar Jan 13 '25 09:01 cleptric

@cleptric do you have any idea when this will be done?

nesl247 avatar Jan 20 '25 18:01 nesl247

Can't give you an estimate on this right now.

cleptric avatar Jan 20 '25 19:01 cleptric