fix: AuthorityResourceMetadata.reload() 동시성 개선(제자리 변이로 인한 ConcurrentModificationException 방지)#242
Open
z3rotig4r wants to merge 1 commit into
Open
Conversation
AuthorityResourceMetadata.reload()는 static authorityList/resourceMap을 clear()+add()로 제자리 변이했다. getAuthorities()/getRoles()가 요청마다 같은 리스트를 순회·반환하므로, 권한 재설정과 동시에 ConcurrentModificationException이 발생하거나 부분(빈) 상태가 읽힐 수 있었다. 새 리스트를 만들어 static 참조를 원자적으로 교체하고 필드를 volatile로 선언해, 읽는 쪽이 항상 완전한 스냅샷만 보도록 한다. 동시 reload/읽기에서 예외가 발생하지 않는지 검증하는 동시성 테스트를 추가한다.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
수정 사유 Reason for modification
수정된 소스 내용 Modified source
reload()가 static 리스트(authorityList,resourceMap)를clear()후add()로 직접 비우고 다시 채웁니다. 이 리스트는EgovUserDetailsHelper.getAuthorities()/getRoles()가 요청마다 읽습니다.그래서 권한을
reload()하는 도중 요청이 들어오면 순회 중에ConcurrentModificationException이 나거나, 비우고 채우는 사이의 빈 리스트가 읽힙니다.reload()는 재기동 없이 권한을 갱신하려는 용도라 트래픽이 도는 중에 호출됩니다.새
ArrayList를 만들어 참조만 바꾸도록 고쳤고, 두 필드는volatile로 뒀습니다. 읽는 쪽은 항상 다 채워진 리스트를 보게 되고, 내용은 기존과 동일합니다.변경 파일:
AuthorityResourceMetadata.java.JUnit 테스트 JUnit tests
AuthorityResourceMetadataConcurrencyTest를 추가했습니다.reload()와 리스트 순회를 16개 스레드로 동시에 돌립니다. 동시성 경합이라 수동 조작으로는 재현이 어렵고, 이 테스트로 확인합니다. 고치기 전에는ConcurrentModificationException으로 실패하고, 고친 뒤 통과합니다.테스트 브라우저 Test Browser
해당 없음.
테스트 스크린샷 또는 캡처 영상 Test screenshots or captured video
해당 없음.