From 522ca206be50b1a39106b85c8b727f7beb9bb98f Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Sun, 21 Dec 2025 23:23:15 -0800 Subject: [PATCH] refactor: clean up code quality issues Remove no-op assignment (calculatedPort = calculatedPort) that had no effect. The variable already holds the correct value when no alternative port is found. Improve documentation for the defensive gRPC port initialization fallback in startAdminServer. While this code shouldn't execute in normal flow because ensureAllPortsAvailableOnIP is called earlier in runMini, the fallback handles edge cases where port initialization may have been skipped or failed silently due to configuration changes or error handling paths. --- weed/command/mini.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/weed/command/mini.go b/weed/command/mini.go index 12d51a8f0..fc359f904 100644 --- a/weed/command/mini.go +++ b/weed/command/mini.go @@ -527,7 +527,6 @@ func initializeGrpcPortsOnIP(bindIp string) { newPort := findAvailablePortOnIP(bindIp, calculatedPort+1, 100, allocatedGrpcPorts) if newPort == 0 { 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) - calculatedPort = 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) @@ -935,6 +934,8 @@ func startMiniAdminWithWorker(allServicesReady chan struct{}) { // gRPC port should have been initialized by ensureAllPortsAvailableOnIP in runMini // If it's still 0, that indicates a problem with the port initialization sequence + // This defensive fallback handles edge cases where port initialization may have been skipped + // or failed silently (e.g., due to configuration changes or error handling paths) if *miniAdminOptions.grpcPort == 0 { glog.Warningf("Admin gRPC port was not initialized before startAdminServer, attempting fallback initialization...") // Use the same availability checking logic as initializeGrpcPortsOnIP