fix: EgovReloadableFilterInvocationSecurityMetadataSource.reload() 동시성 개선(원자적 맵 교체)#267
Open
z3rotig4r wants to merge 1 commit into
Open
Conversation
…성 개선(원자적 맵 교체) reload()가 기존 requestMap을 clear() 후 재적재하는데, 이 맵은 보안 필터 요청 처리 핫패스인 getAttributes()·getAllConfigAttributes()에서 순회된다. 관리 스레드가 재적재하는 동안 요청 스레드가 같은 맵을 순회하면 ConcurrentModificationException이 발생하거나, 재적재가 끝나기 전의 빈/부분 맵을 관측해 권한이 일시적으로 비어 인가 판단이 어긋날 수 있다. 새 LinkedHashMap을 완성한 뒤 requestMap 참조를 한 번에 교체하도록 변경하고, 필드를 volatile로 선언해 완성된 맵의 가시성과 원자적 교체를 보장한다. 순회 스레드는 항상 완전한 맵만 관측한다. 동일 패턴은 AuthorityResourceMetadata.reload()(eGovFramework#242)에서 개선된 바 있다. 테스트: 읽기 순회와 reload 2000회 반복 동시 실행 시 예외 0, 관측 권한 수 최솟값이 항상 20.
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.
배경
EgovReloadableFilterInvocationSecurityMetadataSource.reload()는 기존requestMap을clear()한 뒤 새 항목으로 다시 채웁니다. 이 맵은 보안 필터의 요청 처리 핫패스인getAttributes()·getAllConfigAttributes()에서 순회됩니다.관리 스레드가
reload()로 맵을 비우고 채우는 동안 요청 스레드가 같은 맵을 순회하면,ConcurrentModificationException이 발생하거나 재적재가 끝나기 전의 빈/부분 맵을 관측해 일시적으로 권한이 비어 인가 판단이 어긋날 수 있습니다.변경 내용
reload()가 새LinkedHashMap을 완성한 뒤requestMap참조를 한 번에 교체하도록 변경합니다. 필드는volatile로 선언해 완성된 맵의 가시성과 원자적 교체를 보장합니다. 순회 스레드는 항상 완전한 맵(교체 전 또는 교체 후)만 관측하며, 중간 상태를 볼 수 없습니다.같은 패턴의 in-place 변이 문제는 이미
AuthorityResourceMetadata.reload()에서 원자적 교체로 개선된 바 있습니다(PR#242).테스트
읽기 스레드가
getAllConfigAttributes()를 반복 순회하는 동안 다른 스레드가reload()를 2000회 반복하는 동시성 테스트를 추가했습니다. 예외가 발생하지 않고, 읽기 스레드가 관측한 권한 수의 최솟값이 항상 완전한 값(20)임을 단정합니다. 기존clear()+put()방식이면 부분 맵(20 미만)이 관측되어 이 단정이 깨집니다.영향
getAttributes()·getAllConfigAttributes()의 반환 동작은 동일하며, 동시 재적재 상황에서의 안정성만 개선됩니다.