refactor(grpc): bind TCP listener before etcd registration to prevent connection issues

- Change tokio-stream dependency to include net feature for TcpListenerStream
- Move TCP listener binding before etcd registry initialization in main function
- Pass pre-bound TcpListener to gRPC server instead of just SocketAddr
- Update gRPC server to use serve_with_incoming with TcpListenerStream
- Prevent peers from attempting connections before gRPC server is ready
- Ensure proper error handling for TCP binding failures during startup
This commit is contained in:
zhenyi
2026-06-11 23:07:36 +08:00
parent b797e360c0
commit 5f4e9bdfa7
3 changed files with 15 additions and 7 deletions
+2 -1
View File
@@ -27,6 +27,7 @@ use crate::service::AppService;
pub async fn start_grpc_server(
addr: SocketAddr,
listener: tokio::net::TcpListener,
service: AppService,
) -> Result<(), Box<dyn std::error::Error>> {
let token_svc = auth::TokenGrpcService::new(service.internal_auth.clone());
@@ -60,7 +61,7 @@ pub async fn start_grpc_server(
.add_service(VoiceServiceServer::new(cs.voice))
.add_service(StageServiceServer::new(cs.stage))
.add_service(ChannelAuditServiceServer::new(cs.channel_audit))
.serve(addr)
.serve_with_incoming(tokio_stream::wrappers::TcpListenerStream::new(listener))
.await?;
Ok(())