fix: address code review comments on mini.go port allocation
- Remove flawed fallback gRPC port initialization and convert to fatal error
(ensures port initialization issues are caught immediately instead of silently
failing with an empty reserved ports map)
- Extract common port validation logic to eliminate duplication between
calculated and explicitly set gRPC port handling
glog.Errorf("Could not find available gRPC port for %s starting from %d, will use calculated %d and fail on binding",config.name,calculatedPort+1,calculatedPort)
}else{
calculatedPort=newPort
glog.Infof("gRPC port %d for %s is available, using it instead of calculated %d",newPort,config.name,*config.httpPort+GrpcPortOffset)
}
}
*config.grpcPort=calculatedPort
allocatedGrpcPorts[calculatedPort]=true
glog.V(1).Infof("%s gRPC port initialized to %d",config.name,calculatedPort)
}else{
// gRPC port was explicitly set, verify it's still available (check on both specific IP and all interfaces)
// Also check if it was already allocated to another service in this function
glog.Errorf("Could not find available gRPC port for %s starting from %d, will use original %d and fail on binding",config.name,*config.grpcPort+1,*config.grpcPort)
}else{
glog.Infof("gRPC port %d for %s is available, using it instead of %d",newPort,config.name,*config.grpcPort)
*config.grpcPort=newPort
}
*config.grpcPort=*config.httpPort+GrpcPortOffset
}
// Verify the gRPC port is available (whether calculated or explicitly set)
// Check on both specific IP and all interfaces, and check against already allocated ports
glog.Errorf("Could not find available gRPC port for Admin starting from %d, will use calculated %d and fail on binding",calculatedPort+1,calculatedPort)
*miniAdminOptions.grpcPort=calculatedPort
}else{
glog.Infof("Fallback: using gRPC port %d for Admin",newPort)
*miniAdminOptions.grpcPort=newPort
}
}else{
*miniAdminOptions.grpcPort=calculatedPort
glog.Infof("Fallback: Admin gRPC port initialized to %d",calculatedPort)
}
glog.Fatalf("Admin gRPC port was not initialized before startAdminServer. This indicates a problem with the port initialization sequence.")