{"record":{"id":"500adbcf91497da4","repo":"openimsdk/open-im-server","slug":"standalone-api-port-is-0","errorCode":null,"errorMessage":"standalone api port is 0","messagePattern":"standalone api port is 0","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/main.go","lineNumber":457,"sourceCode":"\t\tnames = append(names, name)\n\t}\n\treturn names\n}\n\ntype serverConfig struct {\n\tAPI         config.API\n\tShare       config.Share\n\tRedisConfig config.Redis\n\tIndex       config.Index\n}\n\nfunc startRedisServerRegister(ctx context.Context, cfg *serverConfig, client discovery.SvcDiscoveryRegistry, service grpc.ServiceRegistrar) error {\n\tapiPort, err := datautil.GetElemByIndex(cfg.API.Api.Ports, int(cfg.Index))\n\tif err != nil {\n\t\treturn err\n\t}\n\tif apiPort <= 0 {\n\t\treturn errors.New(\"standalone api port is 0\")\n\t}\n\tregisterIP, err := network.GetRpcRegisterIP(cfg.API.Api.RegisterIP)\n\tif err != nil {\n\t\treturn err\n\t}\n\tconst validTime = time.Second * 10\n\tdbb := dbbuild.NewBuilder(nil, &cfg.RedisConfig)\n\trdb, err := dbb.Redis(ctx)\n\tif err != nil {\n\t\treturn err\n\t}\n\tgateway := redis.NewStandaloneGatewayRedis(rdb, validTime)\n\tselfAddr := net.JoinHostPort(registerIP, strconv.Itoa(apiPort))\n\tinprocess.SetLocalTarget(selfAddr)\n\tinprocess.SetBroadcastAddress(cfg.Share.Secret, func(ctx context.Context) ([]string, error) {\n\t\taddress, err := gateway.GetGatewayAddrs(ctx)\n\t\tif err != nil {\n\t\t\treturn nil, err","sourceCodeStart":439,"sourceCodeEnd":475,"githubUrl":"https://github.com/openimsdk/open-im-server/blob/175a7bb0673eca18e9d1b10bff4f728da6b1b513/cmd/main.go#L439-L475","documentation":"In standalone (non-cluster) mode the API server's port is selected by indexing cfg.API.Api.Ports with the instance index. If the resolved port is <= 0, startRedisServerRegister refuses to register the service with the error 'standalone api port is 0'. A non-positive port can never be a valid listen address, so startup is aborted.","triggerScenarios":"cfg.Index exceeds the length or maps to no entry of api.ports, or the ports list contains 0/negative values, so datautil.GetElemByIndex returns <=0 and the guard trips.","commonSituations":"Standalone deployment where api.ports was left empty or as [0] placeholder; running more instances than ports defined; copy-paste config from cluster mode where ports are unused.","solutions":["Set api.ports in the config to a list of valid positive ports, e.g. [10002]","Ensure the instance index (cfg.Index) is within range of the ports list","If running multiple instances, provide one port per instance"],"exampleFix":"// before (config)\napi: { ports: [] }          # resolves to 0\n// after\napi: { ports: [10002] }     # one valid port per instance","handlingStrategy":"validation","validationCode":"ports := cfg.API.Api.Ports\nif len(ports) == 0 || cfg.Index >= len(ports) || ports[cfg.Index] <= 0 {\n\treturn fmt.Errorf(\"standalone api port missing for index %d\", cfg.Index)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always define one positive port per instance in api.ports for standalone mode","Validate the config at deploy time (ports non-empty and > 0)","Keep instance count <= len(api.ports)"],"tags":["configuration","grpc","startup","standalone"],"backgroundTag":"invalid-port-configuration","analyzedSha":"175a7bb0673eca18e9d1b10bff4f728da6b1b513","analyzedAt":"2026-09-04T16:52:56.821Z","contentChangedAt":"2026-09-04T16:52:56.821Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}