Skip to content

Commit 1ab6e3d

Browse files
authored
fix(celery): Close the connection we're reading driver_type from (#5427)
Currently, we're reading the driver type (e.g. `redis`) from a connection. We're however not closing the connection, potentially causing file descriptor leaks. **Aside:** Opening a connection just for the purpose of determining the driver type is not ideal in the first place. We should see whether we can get the info from elsewhere from the context of a task's `run`/`__call__` (which is where we're enriching the span with it). Or we could see whether we can cache this somehow. For now, let's at least make sure to clean up the connection. #### Issues Closes #5422 #### Reminders - Please add tests to validate your changes, and lint your code using `tox -e linters`. - Add GH Issue ID _&_ Linear ID (if applicable) - PR title should use [conventional commit](https://develop.sentry.dev/engineering-practices/commit-messages/#type) style (`feat:`, `fix:`, `ref:`, `meta:`) - For external contributors: [CONTRIBUTING.md](https://github.com/getsentry/sentry-python/blob/master/CONTRIBUTING.md), [Sentry SDK development docs](https://develop.sentry.dev/sdk/), [Discord community](https://discord.gg/Ww9hbqr)
1 parent 3373da2 commit 1ab6e3d

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

sentry_sdk/integrations/celery/__init__.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -392,10 +392,11 @@ def _inner(*args: "Any", **kwargs: "Any") -> "Any":
392392
)
393393

394394
with capture_internal_exceptions():
395-
span.set_data(
396-
SPANDATA.MESSAGING_SYSTEM,
397-
task.app.connection().transport.driver_type,
398-
)
395+
with task.app.connection() as conn:
396+
span.set_data(
397+
SPANDATA.MESSAGING_SYSTEM,
398+
conn.transport.driver_type,
399+
)
399400

400401
return f(*args, **kwargs)
401402
except Exception:

0 commit comments

Comments
 (0)