-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(simapp/v2): failed to start HTTP server on port 8080 conflict #22687
Changes from all commits
d5cb12b
9f6d375
488d316
794675a
33a74d0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ import ( | |
runtimev2 "cosmossdk.io/runtime/v2" | ||
serverv2 "cosmossdk.io/server/v2" | ||
"cosmossdk.io/server/v2/api/grpc" | ||
"cosmossdk.io/server/v2/api/rest" | ||
"cosmossdk.io/server/v2/cometbft" | ||
"cosmossdk.io/server/v2/store" | ||
banktypes "cosmossdk.io/x/bank/types" | ||
|
@@ -184,6 +185,7 @@ func initTestnetFiles[T transaction.Tx]( | |
rpcPort = 26657 | ||
apiPort = 1317 | ||
grpcPort = 9090 | ||
restPort = 8080 | ||
) | ||
p2pPortStart := 26656 | ||
|
||
|
@@ -192,6 +194,7 @@ func initTestnetFiles[T transaction.Tx]( | |
for i := 0; i < args.numValidators; i++ { | ||
var portOffset int | ||
grpcConfig := grpc.DefaultConfig() | ||
restConfig := rest.DefaultConfig() | ||
if args.singleMachine { | ||
portOffset = i | ||
p2pPortStart = 16656 // use different start point to not conflict with rpc port | ||
|
@@ -205,6 +208,11 @@ func initTestnetFiles[T transaction.Tx]( | |
MaxRecvMsgSize: grpc.DefaultConfig().MaxRecvMsgSize, | ||
MaxSendMsgSize: grpc.DefaultConfig().MaxSendMsgSize, | ||
} | ||
|
||
restConfig = &rest.Config{ | ||
Enable: true, | ||
Address: fmt.Sprintf("127.0.0.1:%d", restPort+portOffset), | ||
} | ||
Comment on lines
+211
to
+215
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Potential port conflicts in multi-host configurations The REST server is configured to listen on Suggestion: Make the REST port configurable or apply To prevent potential port conflicts in multi-host configurations, consider making the REST port configurable regardless of the |
||
} | ||
|
||
nodeDirName := fmt.Sprintf("%s%d", args.nodeDirPrefix, i) | ||
|
@@ -338,7 +346,8 @@ func initTestnetFiles[T transaction.Tx]( | |
cometServer := cometbft.NewWithConfigOptions[T](cometbft.OverwriteDefaultConfigTomlConfig(nodeConfig)) | ||
storeServer := &store.Server[T]{} | ||
grpcServer := grpc.NewWithConfigOptions[T](grpc.OverwriteDefaultConfig(grpcConfig)) | ||
server := serverv2.NewServer[T](serverCfg, cometServer, storeServer, grpcServer) | ||
restServer := rest.NewWithConfigOptions[T](rest.OverwriteDefaultConfig(restConfig)) | ||
server := serverv2.NewServer[T](serverCfg, cometServer, storeServer, grpcServer, restServer) | ||
err = server.WriteConfig(filepath.Join(nodeDir, "config")) | ||
if err != nil { | ||
return err | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using fixed port
8080
for REST server may cause port conflictsDefining
restPort
as a constant with the value8080
could lead to port conflicts since port8080
is commonly used by other services. Consider making the REST port configurable or choosing an uncommon default port to avoid potential conflicts.