Skip to content

fix: AuthorityResourceMetadata.reload() 동시성 개선(제자리 변이로 인한 ConcurrentModificationException 방지)#242

Open
z3rotig4r wants to merge 1 commit into
eGovFramework:mainfrom
z3rotig4r:fix/access-authority-reload-race
Open

fix: AuthorityResourceMetadata.reload() 동시성 개선(제자리 변이로 인한 ConcurrentModificationException 방지)#242
z3rotig4r wants to merge 1 commit into
eGovFramework:mainfrom
z3rotig4r:fix/access-authority-reload-race

Conversation

@z3rotig4r

@z3rotig4r z3rotig4r commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

수정 사유 Reason for modification

  • 버그수정 Bug fixes
  • 기능개선 Enhancements
  • 기능추가 Adding features
  • 기타 Others

수정된 소스 내용 Modified source

reload()가 static 리스트(authorityList, resourceMap)를 clear()add()로 직접 비우고 다시 채웁니다. 이 리스트는 EgovUserDetailsHelper.getAuthorities()/getRoles()가 요청마다 읽습니다.

그래서 권한을 reload()하는 도중 요청이 들어오면 순회 중에 ConcurrentModificationException이 나거나, 비우고 채우는 사이의 빈 리스트가 읽힙니다. reload()는 재기동 없이 권한을 갱신하려는 용도라 트래픽이 도는 중에 호출됩니다.

ArrayList를 만들어 참조만 바꾸도록 고쳤고, 두 필드는 volatile로 뒀습니다. 읽는 쪽은 항상 다 채워진 리스트를 보게 되고, 내용은 기존과 동일합니다.

변경 파일: AuthorityResourceMetadata.java.

JUnit 테스트 JUnit tests

  • JUnit 테스트 JUnit tests
  • 수동 테스트 Manual testing

AuthorityResourceMetadataConcurrencyTest를 추가했습니다. reload()와 리스트 순회를 16개 스레드로 동시에 돌립니다. 동시성 경합이라 수동 조작으로는 재현이 어렵고, 이 테스트로 확인합니다. 고치기 전에는 ConcurrentModificationException으로 실패하고, 고친 뒤 통과합니다.

테스트 브라우저 Test Browser

해당 없음.

테스트 스크린샷 또는 캡처 영상 Test screenshots or captured video

해당 없음.

AuthorityResourceMetadata.reload()는 static authorityList/resourceMap을
clear()+add()로 제자리 변이했다. getAuthorities()/getRoles()가 요청마다
같은 리스트를 순회·반환하므로, 권한 재설정과 동시에 ConcurrentModificationException이
발생하거나 부분(빈) 상태가 읽힐 수 있었다.

새 리스트를 만들어 static 참조를 원자적으로 교체하고 필드를 volatile로 선언해,
읽는 쪽이 항상 완전한 스냅샷만 보도록 한다. 동시 reload/읽기에서 예외가
발생하지 않는지 검증하는 동시성 테스트를 추가한다.
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.

1 participant