-
Notifications
You must be signed in to change notification settings - Fork 379
[3단계 - Transaction 적용하기] 링크(손준형) 미션 제출합니다. #1158
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: sonjh919
Are you sure you want to change the base?
Changes from all commits
3a3e429
982aba7
c65efea
39be9d5
a7b9f73
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,6 +28,17 @@ public static Connection getConnection(DataSource dataSource) throws CannotGetJd | |
| } | ||
|
|
||
| public static void releaseConnection(Connection connection, DataSource dataSource) { | ||
| if (connection == null) { | ||
| return; | ||
| } | ||
|
|
||
| // 트랜잭션 컨텍스트에서 관리되는 Connection인 경우 닫지 않음 | ||
| Connection boundConnection = TransactionSynchronizationManager.getResource(dataSource); | ||
| if (boundConnection == connection) { | ||
| return; | ||
| } | ||
|
|
||
|
Comment on lines
+31
to
+40
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 치명적: 트랜잭션 외부에서 커넥션 누수 가능성 현재 동작 조합:
트랜잭션이 없는 일반 JdbcTemplate 호출에서도 커넥션이 바인딩되고, JdbcTemplate의 finally에서 releaseConnection이 “바인딩됨”을 이유로 닫지 않아 스레드-로컬에 남을 수 있습니다. 서비스 계층이 unbind를 수행하지 않는 한 커넥션이 장시간 유지/고갈될 위험이 있습니다. 개선 방향(설계 힌트):
왜 중요한가: 리소스 누수는 장애로 직결되며, 테스트 환경에서는 드러나지 않고 운영에서만 표면화됩니다. |
||
| // 트랜잭션 컨텍스트에 없는 Connection만 닫음 | ||
| try { | ||
| connection.close(); | ||
| } catch (SQLException ex) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
치명적: 비(非)트랜잭션 경로에서 커넥션 해제가 되지 않을 수 있음
execute()가 finally에서 releaseConnection을 호출하지만, DataSourceUtils가 “바인딩된 커넥션은 닫지 않음”으로 정의되어 있어 트랜잭션이 없는 호출에서도 커넥션이 닫히지 않을 수 있습니다. 현재 DataSourceUtils는 getConnection 시 무조건 바인딩하므로 둘의 결합으로 누수가 발생합니다.
해결 방향(설계 힌트):
왜 중요한가: 커넥션 풀 고갈, 요청 지연/장애로 직결됩니다.
Also applies to: 143-145
🤖 Prompt for AI Agents