1fix: prevent duplicate TCP bootstrap server creation - #7012
Open
lymerin wants to merge 1 commit into
Open
Conversation
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.
Fixes #6735.
What is changed
TcpProxySelectorDataHandlerpreviously used a non-atomic check-then-act sequence:Concurrent selector synchronization events could both observe a cache miss and start bootstrap servers for the same selector. This could cause port binding failures or leave an overwritten server and its event-loop resources without lifecycle management.
This change:
TcpBootstrapFactory;ConcurrentHashMapatomic callbacks and without a global lifecycle lock;putIfAbsentwhen publishing the started server and shuts down a losing instance if another server was already cached;TcpProxySelectorDataHandlerthrough the atomic creation and removal methods;LoopResourceswhen bootstrap startup fails;TcpBootstrapServer.shutdown()idempotent and preserves shutdown failures using suppressed exceptions.The change is limited to the duplicate bootstrap creation and related resource lifecycle described in #6735. Existing selector configuration update behavior is unchanged.
Tests
Added or extended tests covering:
The following targeted Maven build passed locally:
mvn -pl shenyu-protocol/shenyu-protocol-tcp,shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-tcp \ -am \ -Dtest=TcpBootstrapFactoryTest,TcpBootstrapServerTest,TcpProxySelectorDataHandlerTest \ -Dsurefire.failIfNoSpecifiedTests=false \ testResults:
TcpBootstrapServerTest: 11 tests passedTcpBootstrapFactoryTest: 4 tests passedTcpProxySelectorDataHandlerTest: 3 tests passedChecklist
./mvnw clean install -Dmaven.javadoc.skip=truebuild.