Skip to content

[FIX/#113] Finance MBTI 테스트 데드락 개선 및 트랜잭션 범위 재조정#115

Merged
seamooll merged 4 commits intomainfrom
fix/#113-finance-mbti-deadlock
Feb 18, 2026
Merged

[FIX/#113] Finance MBTI 테스트 데드락 개선 및 트랜잭션 범위 재조정#115
seamooll merged 4 commits intomainfrom
fix/#113-finance-mbti-deadlock

Conversation

@seamooll
Copy link
Contributor

@seamooll seamooll commented Feb 18, 2026

🔗 Related Issue

📝 Summary

  • Lock wait timeout 데드락
    • 문제: 트랜잭션 내부에 외부 API 호출이 포함되어 DB 락 점유 시간이 길어지며 데드락 발생
    • 해결: 클래스 레벨 트랜잭션을 제거하고, 외부 API 호출과 DB 삭제 로직을 분리하여 트랜잭션 범위를 최소화함
  • DB 커넥션 풀 고갈
    • 문제: 중첩된 @Transactional(REQUIRES_NEW) 구조에서 API 응답을 기다리는 동안 인당 2개의 커넥션을 장시간 점유
    • 해결: @Transactional 범위를 재조정하고 DB 저장 전용 서비스(AssetPersistService)를 신설하여 커넥션 점유 시간을 단축
  • 스레드풀 분리 및 Feign 타임아웃 설정
    • 문제: 부모와 자식 스레드가 같은 풀을 공유하여 서로의 실행을 막는 Thread Starvation 위험 발생
    • 해결: 레이어별 전용 스레드 풀을 신설하여 격리하고, Feign 클라이언트에 명시적인 타임아웃 설정을 적용해 무한 대기를 방지함

🔄 Changes

  • API 변경 (추가/수정)
  • 데이터 및 도메인 변경 (DB, 비즈니스 로직)
  • 설정 또는 인프라 관련 변경
  • 리팩토링

💬 Questions & Review Points

📸 API Test Results (Swagger)

✅ Checklist

  • API 테스트 완료
  • 테스트 결과 사진 첨부
  • 빌드 성공 확인 (./gradlew build)

@seamooll seamooll self-assigned this Feb 18, 2026
@seamooll seamooll added 🛠️ fix 버그 수정 도희 도희 labels Feb 18, 2026
@seamooll seamooll linked an issue Feb 18, 2026 that may be closed by this pull request
4 tasks
@gemini-code-assist
Copy link

Summary of Changes

Hello @seamooll, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

이 Pull Request는 시스템의 성능과 안정성을 저해하던 데드락, DB 커넥션 풀 고갈, 스레드 스타베이션 문제를 해결하기 위한 광범위한 리팩토링을 포함합니다. 주요 변경 사항은 트랜잭션 범위를 세밀하게 조정하고, 외부 API 호출과 DB 작업을 분리하며, 비동기 처리 로직을 개선하여 리소스 점유 시간을 최소화하고 동시성을 향상시키는 데 중점을 둡니다.

Highlights

  • 데드락 개선: 트랜잭션 내 외부 API 호출로 인한 DB 락 점유 시간 증가 문제를 해결하기 위해 클래스 레벨 트랜잭션을 제거하고 외부 API 호출과 DB 삭제 로직을 분리하여 트랜잭션 범위를 최소화했습니다.
  • DB 커넥션 풀 고갈 방지: 중첩된 @transactional(REQUIRES_NEW) 구조에서 API 응답 대기 중 커넥션 장기 점유 문제를 해결하기 위해 @transactional 범위를 재조정하고 AssetPersistService를 신설하여 커넥션 점유 시간을 단축했습니다.
  • 스레드풀 격리 및 Feign 타임아웃 설정: 부모-자식 스레드 간 스레드 스타베이션 위험을 방지하기 위해 레이어별 전용 스레드 풀을 신설하여 격리하고, Feign 클라이언트에 명시적인 타임아웃을 설정하여 무한 대기를 방지했습니다.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • src/main/java/org/umc/valuedi/domain/asset/service/command/AssetFetchService.java
    • EntityManager 및 여러 Repository 의존성을 제거했습니다.
    • @transactional 어노테이션을 삭제했습니다.
    • 데이터 영속화 로직을 AssetPersistService로 위임했습니다.
    • fetchAndConvertData 호출 방식을 변경했습니다.
  • src/main/java/org/umc/valuedi/domain/asset/service/command/AssetPersistService.java
    • 자산 데이터의 DB 저장 전용 서비스로 새로 추가되었습니다.
    • @transactional(propagation = Propagation.REQUIRES_NEW)를 사용하여 짧은 트랜잭션 내에서 은행 거래 및 카드 승인 데이터를 필터링하고 저장하는 로직을 포함합니다.
  • src/main/java/org/umc/valuedi/domain/asset/service/command/AssetSyncProcessor.java
    • runSyncProcess 메서드에서 @transactional 어노테이션을 제거했습니다.
    • 비동기 실행자 이름을 assetFetchExecutor에서 assetSyncExecutor로 변경했습니다.
    • member.updateLastSyncedAt() 호출을 ledgerSyncService.updateMemberLastSyncedAt(memberId)로 대체했습니다.
  • src/main/java/org/umc/valuedi/domain/asset/service/command/AssetSyncService.java
    • 클래스 레벨의 @transactional 어노테이션을 제거했습니다.
    • rebuildLedger 호출 후 ledgerSyncService.updateMemberLastSyncedAt(member.getId())를 추가했습니다.
  • src/main/java/org/umc/valuedi/domain/asset/service/command/worker/AssetFetchWorker.java
    • TransactionTemplate과 CodefConnectionRepository를 주입받도록 변경했습니다.
    • fetchAndConvertData 메서드가 connectionId를 인자로 받아 트랜잭션 내에서 CodefConnection을 조회하도록 수정했습니다.
    • 카드 저장 로직을 TransactionTemplate.execute 블록으로 감싸 트랜잭션 경계를 명확히 했습니다.
  • src/main/java/org/umc/valuedi/domain/connection/repository/CodefConnectionRepository.java
    • findByIdWithAccountsAndMember라는 새로운 쿼리 메서드를 추가하여 연결된 계좌 정보와 함께 CodefConnection을 조회할 수 있도록 했습니다.
  • src/main/java/org/umc/valuedi/domain/connection/service/command/ConnectionCommandService.java
    • 클래스 레벨의 @transactional 어노테이션을 제거했습니다.
    • connect 및 disconnect 메서드를 외부 API 호출과 DB 작업으로 분리했습니다.
    • DB 삭제 로직을 ConnectionDeleteCommandService로 위임했습니다.
    • GoalRepository 의존성을 제거했습니다.
  • src/main/java/org/umc/valuedi/domain/connection/service/command/ConnectionDeleteCommandService.java
    • CodefConnection 및 관련 데이터를 짧은 트랜잭션 내에서 소프트 딜리트하는 전용 서비스로 새로 추가되었습니다.
  • src/main/java/org/umc/valuedi/domain/connection/service/event/ConnectionEventListener.java
    • @async 어노테이션의 실행자 이름을 assetFetchExecutor에서 assetSyncExecutor로 변경했습니다.
  • src/main/java/org/umc/valuedi/domain/ledger/service/command/LedgerSyncService.java
    • rebuildLedger 메서드에서 member.updateLastSyncedAt() 호출을 제거했습니다.
  • src/main/java/org/umc/valuedi/domain/savings/service/RecommendationService.java
    • generateAndSaveRecommendations 메서드에서 @transactional 어노테이션을 제거했습니다.
  • src/main/java/org/umc/valuedi/global/config/AsyncConfig.java
    • assetSyncExecutor라는 새로운 비동기 실행자 빈을 추가했습니다.
    • assetFetchExecutor의 스레드 풀 크기를 조정했습니다.
  • src/main/java/org/umc/valuedi/global/external/codef/config/CodefFeignConfig.java
    • Feign 클라이언트에 대한 타임아웃 설정을 포함하는 Request.Options 빈을 추가했습니다.
  • src/main/java/org/umc/valuedi/global/external/codef/service/CodefAccountService.java
    • connectAccount 메서드를 findExistingConnectedId, callCodefConnectApi, saveConnection으로 분리하여 책임과 트랜잭션 경계를 명확히 했습니다.
    • CodefConnectionRepository와 MemberRepository 의존성을 추가했습니다.
  • src/main/resources/application.yml
    • HikariCP 커넥션 풀의 maximum-pool-size와 leak-detection-threshold 설정을 추가했습니다.
Activity
  • 이 Pull Request는 현재까지 특별한 리뷰 활동이나 코멘트가 기록되지 않았습니다.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

이번 PR은 데드락 및 커넥션 풀 고갈 문제를 해결하기 위해 트랜잭션 범위를 재조정하고 비동기 처리 로직을 개선하는 중요한 리팩토링을 수행했습니다. 외부 API 호출과 DB 작업을 분리하고, 트랜잭션 범위를 최소화하여 시스템 안정성과 성능을 크게 향상시킨 점이 인상적입니다. 특히 AssetPersistService, ConnectionDeleteCommandService와 같은 새로운 서비스를 도입하여 역할을 명확히 분리하고, TransactionTemplate을 활용하여 비동기 환경에서 트랜잭션을 정교하게 제어한 것은 매우 훌륭한 접근 방식입니다. 또한, 스레드 풀을 분리하고 Feign 클라이언트에 타임아웃을 설정하여 스레드 고갈 및 무한 대기 문제를 방지한 점도 좋습니다.

전반적으로 매우 완성도 높은 변경이지만, 코드의 간결성을 높이고 잠재적인 성능 문제를 방지하기 위해 몇 가지 개선점을 제안했습니다. 제안된 내용을 검토하여 반영해주시면 코드가 더욱 견고해질 것입니다. 훌륭한 작업입니다!

@seamooll seamooll merged commit 177dea2 into main Feb 18, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

도희 도희 🛠️ fix 버그 수정

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FIX] Finance MBTI 테스트 데드락 및 커넥션 풀 고갈 문제 해결

1 participant

Comments