@@ -258,9 +258,7 @@ func (s *Container) Run(
258258 // Start the optional HTTP server with CORS and optional TLS configurations.
259259 // Connect to the gRPC server and register the HTTP handlers for each service.
260260 if srv .HTTP .Enabled {
261- options := []grpc.DialOption {
262- grpc .WithBlock (),
263- }
261+ options := []grpc.DialOption {}
264262 if srv .GRPC .TLSConfig .Enabled {
265263 c , err := credentials .NewClientTLSFromFile (srv .GRPC .TLSConfig .CertPath , srv .NameOverride )
266264 if err != nil {
@@ -271,16 +269,14 @@ func (s *Container) Run(
271269 options = append (options , grpc .WithTransportCredentials (insecure .NewCredentials ()))
272270 }
273271
274- timeoutCtx , cancel := context .WithTimeout (ctx , 3 * time .Second )
275- defer cancel ()
276-
277- conn , err := grpc .DialContext (timeoutCtx , ":" + srv .GRPC .Port , options ... )
272+ targetAddr := net .JoinHostPort (srv .Host , srv .GRPC .Port ) // gRPC server address
273+ conn , err := grpc .NewClient (targetAddr , options ... ) // Create gRPC client connection
278274 if err != nil {
279275 return err
280276 }
281277 defer func () {
282- if err = conn .Close (); err != nil { // Connection close error
283- slog .Error ("Failed to close gRPC connection" , slog .Any ("error" , err )) // Log close error
278+ if closeErr : = conn .Close (); closeErr != nil { // Connection close error
279+ slog .Error ("Failed to close gRPC connection" , slog .Any ("error" , closeErr )) // Log close error
284280 }
285281 }()
286282
@@ -344,9 +340,10 @@ func (s *Container) Run(
344340 }, // Methods configured
345341 }).Handler (mux ) // CORS handler created
346342
347- httpServer = & http.Server { // HTTP server configuration
348- Addr : ":" + srv .HTTP .Port , // Server address
349- Handler : corsHandler , // CORS handler
343+ httpTargetAddr := net .JoinHostPort (srv .Host , srv .HTTP .Port ) // HTTP server address
344+ httpServer = & http.Server { // HTTP server configuration
345+ Addr : httpTargetAddr , // Server address
346+ Handler : corsHandler , // CORS handler
350347 ReadHeaderTimeout : 5 * time .Second ,
351348 }
352349
0 commit comments