fix: Fix segfault during shutdown when using Triton metrics in Python backend - #429
Conversation
|
@aleksn7 thank you for your contribution. Have you completed the required steps outlined in our Contributing section? Specifically, have you submitted a signed CLA? If not, please do so. |
There was a problem hiding this comment.
Pull request overview
Fixes a shutdown-time segmentation fault in the Python backend when Triton custom metrics are enabled by ensuring Python-bound objects are released in a safe order relative to the Stub singleton teardown.
Changes:
- Added
Stub::DestroyPythonObjects()to explicitly drop Python-owned objects beforeStubdestruction. - Updated
Stub::DestroyInstance()to callDestroyPythonObjects()prior to resetting the singleton.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/pb_stub.h | Declares the new DestroyPythonObjects() API and documents intended destructor ordering. |
| src/pb_stub.cc | Calls DestroyPythonObjects() during singleton destruction and implements the cleanup routine. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
This is still blocking:
|
I'm working on it |
|
@whoisj Hello! |
|
CI Pipeline ID: 52832251 |
Hi! Do you have any updates on this? |
|
@aleksn7, apologies for the delay as we've been off work for the past five days. Unfortunately, there are test failures in our CI currently that while unrelated to this PR, are blocking my ability to validate this PR. We'll return to this PR as soon as these test failures have been resolved. Again, my apologies for the delay. |
|
Hi @whoisj, |
|
@pskiran1 , could you please help with this PR? thank you! |
|
@yinggeh , could you please review this PR, thanks |
Problem
When shutting down the Triton Inference Server with Python backend while using Triton metrics, a segmentation fault occurs. This happens because Metric::Clear attempts to access the Stub singleton during the Stub destructor execution.
Stack trace:
Solution
Added a new DestroyPythonObjects() method to the Stub class that explicitly releases all Python objects before the Stub destructor is invoked. This ensures proper destruction order:
DestroyPythonObjects() is called first, releasing all Python-bound objects (including MetricFamily instances)
Stub::~Stub() is called afterward, when no Python objects depend on it
This approach guarantees that MetricFamily and other Python objects are fully destroyed while Stub is still valid and accessible.
To reproduce
Run triton server with custom metric example model and shut it down by
kill -2 <main triton server process pid>