Skip to content

Commit 152a8a6

Browse files
VianneyRuhlmannchristophe-papazian
authored andcommitted
chore(utils): stop threads in dummy writer (#15307)
## Description Fix crash in `appsec_threats` test on macos caused by to many NativeWriter being created. The crash is due to each native writer instance holding onto a kqueue fd exceeding the macos ulimit (256). This fixes the issue by shutting down the tokio runtime of the native writer when we are done with the DummyTracer ie. when pop is called. ## Testing Run the `appsec_threats_fastapi` test with `ulimit -n` set to 256 (by default on mac). --------- Co-authored-by: Christophe Papazian <[email protected]> Co-authored-by: Christophe Papazian <[email protected]>
1 parent 5fd5f69 commit 152a8a6

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

tests/appsec/contrib_appsec/test_fastapi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
class Test_FastAPI(utils.Contrib_TestClass_For_Threats):
1717
@pytest.fixture
18-
def interface(self, tracer, printer):
18+
def interface(self, printer):
1919
from fastapi.testclient import TestClient
2020

2121
# for fastapi, test tracer needs to be set before the app is created

tests/utils.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,10 @@ def pop(self):
644644
spans = DummyWriterMixin.pop(self)
645645
if self._trace_flush_enabled:
646646
flush_test_tracer_spans(self)
647+
# Stop the writer threads in case the writer is no longer used.
648+
# Otherwise we risk accumulating threads and file descriptors causing crashes
649+
# In case the writer is used again it will be restarted by native side.
650+
self._inner_writer.before_fork()
647651
return spans
648652

649653
def recreate(self, appsec_enabled: Optional[bool] = None) -> "DummyWriter":

0 commit comments

Comments
 (0)