-
Notifications
You must be signed in to change notification settings - Fork 1.2k
fix triple shared channel remove when rpc sendMsg issue #1521
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix triple shared channel remove when rpc sendMsg issue #1521
Conversation
WalkthroughReference-counted gRPC channel handling was added and logging introduced. ReferenceCountManagedChannel now holds a final grpcChannel, decrements the reference count on shutdown and fully shuts the underlying channel when count ≤ 0. TripleClientTransport updates increment/decrement usage and disconnect/cleanup behavior. A test verifies shared-channel lifecycle. Changes
Sequence Diagram(s)sequenceDiagram
participant ClientTransport as TripleClientTransport
participant RefChannel as ReferenceCountManagedChannel
participant GRPC as ManagedChannel
Note right of ClientTransport: obtain shared channel
ClientTransport->>RefChannel: getSharedChannel()
alt existing channel
ClientTransport->>RefChannel: incrementAndGetCount()
RefChannel->>RefChannel: referenceCount++
else create new
ClientTransport->>RefChannel: new ReferenceCountManagedChannel(GRPC)
ClientTransport->>RefChannel: incrementAndGetCount()
RefChannel->>RefChannel: referenceCount = 1
end
Note right of ClientTransport: shutdown flow
ClientTransport->>RefChannel: shutdown()
RefChannel->>RefChannel: referenceCount--
alt referenceCount ≤ 0
RefChannel->>GRPC: shutdown()
RefChannel->>GRPC: awaitTermination(5s)
RefChannel->>RefChannel: log termination/result
else referenceCount > 0
RefChannel-->>ClientTransport: return channel (no shutdown)
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~35 minutes
Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (1)
remoting/remoting-triple/src/main/java/com/alipay/sofa/rpc/transport/triple/ReferenceCountManagedChannel.java (1)
61-64: Preserve the interrupt flag after catching InterruptedExceptionWe’re swallowing the interrupt when
awaitTerminationis interrupted, so upstream code will keep running as if nothing happened. Please restore the thread’s interrupt status after logging so callers can react properly.- } catch (InterruptedException e) { - LOGGER.warn("Triple channel shut down interrupted."); + } catch (InterruptedException e) { + LOGGER.warn("Triple channel shut down interrupted."); + Thread.currentThread().interrupt();
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
remoting/remoting-triple/src/main/java/com/alipay/sofa/rpc/transport/triple/ReferenceCountManagedChannel.java(3 hunks)remoting/remoting-triple/src/main/java/com/alipay/sofa/rpc/transport/triple/TripleClientTransport.java(3 hunks)remoting/remoting-triple/src/test/java/com/alipay/sofa/rpc/transport/triple/TripleClientTransportTest.java(2 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
remoting/remoting-triple/src/test/java/com/alipay/sofa/rpc/transport/triple/TripleClientTransportTest.java (4)
core/api/src/main/java/com/alipay/sofa/rpc/client/ProviderInfo.java (1)
ProviderInfo(35-528)core/api/src/main/java/com/alipay/sofa/rpc/config/ConsumerConfig.java (1)
ConsumerConfig(71-1044)core/api/src/main/java/com/alipay/sofa/rpc/transport/ClientTransportConfig.java (1)
ClientTransportConfig(41-299)core/api/src/main/java/com/alipay/sofa/rpc/transport/ClientTransportFactory.java (1)
ClientTransportFactory(36-189)
remoting/remoting-triple/src/main/java/com/alipay/sofa/rpc/transport/triple/ReferenceCountManagedChannel.java (1)
core/api/src/main/java/com/alipay/sofa/rpc/log/LoggerFactory.java (1)
LoggerFactory(29-70)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: build
- GitHub Check: sca
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🧹 Nitpick comments (1)
remoting/remoting-triple/src/main/java/com/alipay/sofa/rpc/transport/triple/TripleClientTransport.java (1)
252-252: Consider deferring shutdownNow() or using plain shutdown().Calling
shutdownNow()on an unavailable channel outside the synchronized block could interfere with other threads that are concurrently checking or using the same channel instance. While the subsequent double-check inside the synchronized block mitigates some risk, this aggressive shutdown might cause unexpected behavior.Consider either:
- Moving the shutdown logic inside the synchronized block after confirming the channel is still unavailable, or
- Using
shutdown()instead ofshutdownNow()to allow graceful termination
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
remoting/remoting-triple/src/main/java/com/alipay/sofa/rpc/transport/triple/TripleClientTransport.java(3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: build
- GitHub Check: sca
🔇 Additional comments (1)
remoting/remoting-triple/src/main/java/com/alipay/sofa/rpc/transport/triple/TripleClientTransport.java (1)
77-77: The static lock design is sound and not a practical bottleneck.While the static lock does create a global synchronization point across all
TripleClientTransportinstances, this is not problematic in practice. The lock is only held briefly during map operations (get,put,incrementAndGetCount()—all microsecond-scale operations). Critically, slow I/O operations likeawaitTermination()occur outside the synchronized block. Additionally, reference counting usesAtomicIntegerfor lock-free increments/decrements, and instances are typically limited to one per distinct remote service—usually a handful to perhaps 50-100 even in large microservice applications. The implementation properly decrementing viaReferenceCountManagedChannel.shutdown()confirms the design is correct.
fix shared channel remove when rpc sendMag issue
Summary by CodeRabbit
Bug Fixes
Refactor
Tests