lymerin opened a new pull request, #7012:
URL: https://github.com/apache/shenyu/pull/7012
Fixes #6735.
## What is changed
`TcpProxySelectorDataHandler` previously used a non-atomic check-then-act
sequence:
```text
inCache -> createBootstrapServer -> cache
```
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:
- adds per-selector single-flight creation in `TcpBootstrapFactory`;
- ensures concurrent creation requests for the same selector wait for one
in-flight creation;
- performs server startup outside `ConcurrentHashMap` atomic callbacks and
without a global lifecycle lock;
- allows different selectors to be created and removed independently;
- uses `putIfAbsent` when publishing the started server and shuts down a
losing instance if another server was already cached;
- routes `TcpProxySelectorDataHandler` through the atomic creation and
removal methods;
- preserves the existing public factory methods for compatibility;
- rolls back `LoopResources` when bootstrap startup fails;
- makes `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:
- concurrent creation of the same selector creates only one server;
- a failed creation can be retried;
- waiting callers receive the original creation failure;
- slow shutdown of one selector does not block removal of another selector;
- bootstrap startup failure disposes its loop resources;
- repeated shutdown is idempotent;
- failures from both server and loop-resource disposal are preserved.
The following targeted Maven build passed locally:
```shell
mvn -pl
shenyu-protocol/shenyu-protocol-tcp,shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-tcp
\
-am \
-Dtest=TcpBootstrapFactoryTest,TcpBootstrapServerTest,TcpProxySelectorDataHandlerTest
\
-Dsurefire.failIfNoSpecifiedTests=false \
test
```
Results:
- `TcpBootstrapServerTest`: 11 tests passed
- `TcpBootstrapFactoryTest`: 4 tests passed
- `TcpProxySelectorDataHandlerTest`: 3 tests passed
- Checkstyle: no violations
## Checklist
- [x] I have read the [[contribution
guidelines](https://shenyu.apache.org/community/contributor-guide)](https://shenyu.apache.org/community/contributor-guide).
- [x] I have submitted test cases that cover the changes.
- [x] I have run the complete `./mvnw clean install
-Dmaven.javadoc.skip=true` build.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]