Skip to content

[ServiceDB] handle exception#70

Merged
myungjoo merged 2 commits intonnstreamer:mainfrom
jaeyun-jung:svcdb-handle-exception
Mar 17, 2026
Merged

[ServiceDB] handle exception#70
myungjoo merged 2 commits intonnstreamer:mainfrom
jaeyun-jung:svcdb-handle-exception

Conversation

@jaeyun-jung
Copy link
Copy Markdown
Contributor

Handle exception when initializing service-db instance.

ml_loge ("%s", e.what ());
svcdb_finalize ();
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code below is right ?

try {
    g_svcdb_instance = new MLServiceDB (path);
    g_svcdb_instance->connectDB ();
    g_assert (g_svcdb_instance);  // when succeed ?
  } catch (const std::exception &e) {
    ml_loge ("%s", e.what ());
    svcdb_finalize ();
  }

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

no, db instance should be a valid pointer when calling initialization.

}

g_svcdb_instance = new MLServiceDB (path);
try {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

add g_svcdb_insatnce = nullptr after line 876.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I used svcdb_finalize()

g_svcdb_instance->connectDB ();
} catch (const std::exception &e) {
ml_loge ("%s", e.what ());
svcdb_finalize ();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is CURSOR's review, and I agree with it:

PR #70 ([ServiceDB] handle exception, commit 0183218) 기준으로 변경분만 리뷰했습니다.

주요 Findings (심각도 순)

[Critical] 예외 경로에서 use-after-free / double-delete 가능

위치: daemon/service-db.cc:874-877, 882-885, 895-899
문제:
기존 인스턴스가 있을 때 delete g_svcdb_instance; 후 nullptr로 초기화하지 않습니다.
그 다음 new MLServiceDB(path)가 예외를 던지면(예: std::bad_alloc, ctor 예외), catch에서 svcdb_finalize()를 호출하면서 이미 해제된 포인터를 다시 disconnectDB()/delete 할 수 있습니다.
제안:
delete 직후 g_svcdb_instance = nullptr;를 즉시 설정.
catch에서 svcdb_finalize() 대신 안전하게 상태만 정리(또는 지역 포인터/std::unique_ptr로 생성 완료 후 전역 포인터에 대입).


[High] “예외 처리” 목적이 실제로는 달성되지 않음 (assert로 종료)

위치: daemon/service-db.cc:879-888
문제:
catch에서 예외를 로그하고 정리한 뒤에도 g_assert(g_svcdb_instance);가 실행됩니다.
실패 시 g_svcdb_instance == nullptr이므로 assert로 프로세스 종료 가능 → 커밋 메시지의 “Handle exception”과 동작 불일치.
제안:
실패를 호출자에게 전달 가능한 형태로 변경(svcdb_initialize 반환형을 int/bool로), 최소한 assert 대신 명시적 에러 경로 처리 필요.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I added new commit to handle error code while initializing ml agent.

Handle exception when initializing service-db instance.

Signed-off-by: Jaeyun Jung <jy1210.jung@samsung.com>
@jaeyun-jung jaeyun-jung force-pushed the svcdb-handle-exception branch from 0183218 to 9e67044 Compare March 17, 2026 03:37
Clearly handle error code when initializing mlops-agent daemon.

Signed-off-by: Jaeyun Jung <jy1210.jung@samsung.com>
@jaeyun-jung jaeyun-jung force-pushed the svcdb-handle-exception branch from d8945bb to 62ccd26 Compare March 17, 2026 05:19
@myungjoo myungjoo merged commit 0e4faa5 into nnstreamer:main Mar 17, 2026
8 checks passed
@jaeyun-jung jaeyun-jung deleted the svcdb-handle-exception branch March 23, 2026 05:34
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