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

fix(flags): Fix bug where concurrent accesses to the flags property could raise a RunTime error #4034

Merged
merged 3 commits into from
Feb 11, 2025

Conversation

cmanallen
Copy link
Member

@cmanallen cmanallen commented Feb 10, 2025

On error the SDK deep copies the flag buffer. If the SDK is receiving flags at the same time, the buffer copy can potentially raise a RunTime error. To fix this we guard the FlagBuffer with a lock.

Fixes: https://sentry.sentry.io/issues/6286673308/?project=1

Copy link

codecov bot commented Feb 10, 2025

❌ 54 Tests Failed:

Tests completed Failed Passed Skipped
22316 54 22262 5758
View the top 3 failed test(s) by shortest run time
pytest internal
Stack Traces | 0s run time
Traceback (most recent call last):
  File ".../sentry-python/sentry-python/.tox/py3.7-falcon-v1.4/lib/python3.7...................../site-packages/coverage/sqldata.py", line 1173, in _execute
    return self.con.execute(sql, parameters)    # type: ignore[arg-type]
sqlite3.OperationalError: no such table: file

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File ".../sentry-python/sentry-python/.tox/py3.7-falcon-v1.4/lib/python3.7...................../site-packages/coverage/sqldata.py", line 1178, in _execute
    return self.con.execute(sql, parameters)    # type: ignore[arg-type]
sqlite3.OperationalError: no such table: file

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File ".../sentry-python/sentry-python/.tox/py3.7-falcon-v1.4/lib/python3.7....../site-packages/_pytest/main.py", line 271, in wrap_session
    session.exitstatus = doit(config, session) or 0
  File ".../sentry-python/sentry-python/.tox/py3.7-falcon-v1.4/lib/python3.7....../site-packages/_pytest/main.py", line 325, in _main
    config.hook.pytest_runtestloop(session=session)
  File ".../sentry-python/sentry-python/.tox/py3.7-falcon-v1.4/lib/python3.7.../site-packages/pluggy/_hooks.py", line 433, in __call__
    return self._hookexec(self.name, self._hookimpls, kwargs, firstresult)
  File ".../sentry-python/sentry-python/.tox/py3.7-falcon-v1.4/lib/python3.7.../site-packages/pluggy/_manager.py", line 112, in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
  File ".../sentry-python/sentry-python/.tox/py3.7-falcon-v1.4/lib/python3.7.../site-packages/pluggy/_callers.py", line 133, in _multicall
    teardown[0].send(outcome)
  File ".../sentry-python/sentry-python/.tox/py3.7-falcon-v1.4/lib/python3.7.../site-packages/pytest_cov/plugin.py", line 298, in pytest_runtestloop
    self.cov_controller.finish()
  File ".../sentry-python/sentry-python/.tox/py3.7-falcon-v1.4/lib/python3.7....../site-packages/pytest_cov/engine.py", line 44, in ensure_topdir_wrapper
    return meth(self, *args, **kwargs)
  File ".../sentry-python/sentry-python/.tox/py3.7-falcon-v1.4/lib/python3.7....../site-packages/pytest_cov/engine.py", line 249, in finish
    self.cov.stop()
  File ".../sentry-python/sentry-python/.tox/py3.7-falcon-v1.4/lib/python3.7........./site-packages/coverage/control.py", line 757, in save
    data = self.get_data()
  File ".../sentry-python/sentry-python/.tox/py3.7-falcon-v1.4/lib/python3.7........./site-packages/coverage/control.py", line 838, in get_data
    self._post_save_work()
  File ".../sentry-python/sentry-python/.tox/py3.7-falcon-v1.4/lib/python3.7........./site-packages/coverage/control.py", line 869, in _post_save_work
    self._data.touch_files(paths, plugin_name)
  File ".../sentry-python/sentry-python/.tox/py3.7-falcon-v1.4/lib/python3.7...................../site-packages/coverage/sqldata.py", line 615, in touch_files
    self._file_id(filename, add=True)
  File ".../sentry-python/sentry-python/.tox/py3.7-falcon-v1.4/lib/python3.7...................../site-packages/coverage/sqldata.py", line 419, in _file_id
    (filename,)
  File ".../sentry-python/sentry-python/.tox/py3.7-falcon-v1.4/lib/python3.7...................../site-packages/coverage/sqldata.py", line 1219, in execute_for_rowid
    with self.execute(sql, parameters) as cur:
  File ".../hostedtoolcache/Python/3.7.17.../x64/lib/python3.7/contextlib.py", line 112, in __enter__
    return next(self.gen)
  File ".../sentry-python/sentry-python/.tox/py3.7-falcon-v1.4/lib/python3.7...................../site-packages/coverage/sqldata.py", line 1207, in execute
    cur = self._execute(sql, parameters)
  File ".../sentry-python/sentry-python/.tox/py3.7-falcon-v1.4/lib/python3.7...................../site-packages/coverage/sqldata.py", line 1195, in _execute
    raise DataError(f"Couldn't use data file {self.filename!r}: {msg}") from exc
coverage.exceptions.DataError: Couldn't use data file '.../sentry-python/sentry-python/.coverage-sentry-py3.7-falcon-v1.4.fv-az890-162.3327.489845': no such table: file
tests.integrations.strawberry.test_strawberry test_handle_none_query_gracefully[async_app_client_factory-True-framework_integrations0]
Stack Traces | 0.064s run time
.../integrations/strawberry/test_strawberry.py:631: in test_handle_none_query_gracefully
    sentry_init(
tests/conftest.py:203: in inner
    client = sentry_sdk.Client(*a, **kw)
sentry_sdk/client.py:269: in __init__
    self._init_impl()
sentry_sdk/client.py:392: in _init_impl
    self.integrations = setup_integrations(
sentry_sdk/integrations/__init__.py:196: in setup_integrations
    type(integration).setup_once()
sentry_sdk/integrations/strawberry.py:81: in setup_once
    _patch_execute()
sentry_sdk/integrations/strawberry.py:293: in _patch_execute
    old_execute_sync = strawberry_schema.execute_sync
E   AttributeError: module 'strawberry.schema.schema' has no attribute 'execute_sync'
tests.integrations.strawberry.test_strawberry test_span_origin[sync_app_client_factory-False-framework_integrations1]
Stack Traces | 0.064s run time
.../integrations/strawberry/test_strawberry.py:661: in test_span_origin
    sentry_init(
tests/conftest.py:203: in inner
    client = sentry_sdk.Client(*a, **kw)
sentry_sdk/client.py:269: in __init__
    self._init_impl()
sentry_sdk/client.py:392: in _init_impl
    self.integrations = setup_integrations(
sentry_sdk/integrations/__init__.py:196: in setup_integrations
    type(integration).setup_once()
sentry_sdk/integrations/strawberry.py:81: in setup_once
    _patch_execute()
sentry_sdk/integrations/strawberry.py:293: in _patch_execute
    old_execute_sync = strawberry_schema.execute_sync
E   AttributeError: module 'strawberry.schema.schema' has no attribute 'execute_sync'

To view more test analytics, go to the Test Analytics Dashboard
📋 Got 3 mins? Take this short survey to help us improve Test Analytics.

@cmanallen
Copy link
Member Author

@antonpirker Strawberry integration seems broken for unrelated reasons.

@cmanallen cmanallen merged commit d937272 into master Feb 11, 2025
149 of 151 checks passed
@cmanallen cmanallen deleted the cmanallen/fix-flags-concurrent-access branch February 11, 2025 15:36
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

Successfully merging this pull request may close these issues.

2 participants