Skip to content

[onert] Ensure proper pipeline cleanup on exceptions and shutdown#16379

Open
batcheu wants to merge 1 commit intoSamsung:masterfrom
batcheu:prevent_resource_leak
Open

[onert] Ensure proper pipeline cleanup on exceptions and shutdown#16379
batcheu wants to merge 1 commit intoSamsung:masterfrom
batcheu:prevent_resource_leak

Conversation

@batcheu
Copy link
Contributor

@batcheu batcheu commented Feb 9, 2026

These changes ensure that pipeline resources are properly released even in error scenarios or when the pipeline was not fully initialized, preventing potential resource leaks.

ONE-DCO-1.0-Signed-off-by: Jonghwa Lee jonghwa3.lee@samsung.com

@batcheu
Copy link
Contributor Author

batcheu commented Feb 9, 2026

It is related below comments by @ragmani.
https://github.com/Samsung/ONE/pull/16349/changes#r2726893075

@batcheu
Copy link
Contributor Author

batcheu commented Feb 9, 2026

@ragmani
I applied your comment, PTAL ;)

}
catch (const std::exception &e)
{
_pipeline_manager->shutdown();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From now on, any of exceptions including 'Asynchronous buffer filling' and 'Model execution' will call shutdown() explicitly to release resources properly.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if BulkPipelineManager::shutdown() is always guaranteed not to throw exceptions. However, the current pipeline are already complex, and I'm don't know how to resolve this issue. So, I want to ignore this and move on to the next stage.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no case of throwing additional exception in BulkPipelineManager::shutdown(). And even if an exception occurrs, it will abandon the previous one and proceed to the next one. 😊

Comment on lines +75 to +85
int nr_fclose_calls = 0;
EXPECT_TRUE(manager->initialize());
// This hook will checking the number of fclose() calls
MockSyscallsManager::getInstance().setFcloseHook([&nr_fclose_calls](FILE *) -> int {
nr_fclose_calls++;
return 0;
});
manager->shutdown();
EXPECT_FALSE(manager->isInitialized());
// fclose() should be called as the same number of models
EXPECT_EQ(nr_fclose_calls, nr_models);
Copy link
Contributor Author

@batcheu batcheu Feb 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is difficult to test the manipulated failure of BulkPipelineBuffer:startAsyncBufferFill(). 😢
However, it is possible to indirectly verify whether resources are released when an issue arises by confirming whether the resources of BulkPipelineBuffer are released upon calling BufferPipelineManager::shutdown().

ragmani
ragmani previously approved these changes Feb 9, 2026
Copy link
Contributor

@ragmani ragmani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@batcheu batcheu marked this pull request as draft February 10, 2026 00:02
These changes ensure that pipeline resources are properly released even
in error scenarios or when the pipeline was not fully initialized,
preventing potential resource leaks.

ONE-DCO-1.0-Signed-off-by: Jonghwa Lee <jonghwa3.lee@samsung.com>
@batcheu batcheu force-pushed the prevent_resource_leak branch from eacffc0 to 6165656 Compare February 10, 2026 00:06
@batcheu batcheu marked this pull request as ready for review February 10, 2026 00:07
void TearDown() override {}

std::unique_ptr<BulkPipelineManager> manager;
const int nr_models = 1;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I missed to update this line in previous PR ;(

-- const int nr_models = 2;
++ const int nr_models = 1;

@batcheu
Copy link
Contributor Author

batcheu commented Feb 10, 2026

LGTM

@ragmani
There was an unupdated line while re-based.
Please approve again;)

Copy link
Contributor

@hseok-oh hseok-oh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

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.

3 participants