Skip to content

Commit

Permalink
Merge pull request #747 from ava-labs/clear-error-msg-is-ports-are-busy
Browse files Browse the repository at this point in the history
give clear err msg if avalanchego port is already taken
  • Loading branch information
felipemadero authored Nov 30, 2024
2 parents f83b675 + e0c13f0 commit a0946c5
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions local/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -530,19 +530,26 @@ func (ln *localNetwork) loadConfig(ctx context.Context, networkConfig network.Co

for i := range nodeConfigs {
if node, nodeErr := ln.addNode(nodeConfigs[i]); nodeErr != nil {
if ln.reassignPortsIfUsed && node != nil {
if node != nil {
if mainLog, err := os.ReadFile(filepath.Join(node.GetLogsDir(), "main.log")); err == nil {
if strings.Contains(string(mainLog), "bind: address already in use") {
ln.log.Info(fmt.Sprintf(
"failed to start node %s with given ports. executing again with dynamic ones.",
nodeConfigs[i].Name,
))
// execute again asking avago to set ports by itself
nodeConfigs[i].Flags[config.HTTPPortKey] = 0
nodeConfigs[i].Flags[config.StakingPortKey] = 0
_, nodeErr = ln.addNode(nodeConfigs[i])
if nodeErr == nil {
continue
if ln.reassignPortsIfUsed {
ln.log.Info(fmt.Sprintf(
"failed to start node %s with given ports. executing again with dynamic ones.",
nodeConfigs[i].Name,
))
// execute again asking avago to set ports by itself
nodeConfigs[i].Flags[config.HTTPPortKey] = 0
nodeConfigs[i].Flags[config.StakingPortKey] = 0
_, nodeErr = ln.addNode(nodeConfigs[i])
if nodeErr == nil {
continue
}
} else {
nodeErr = fmt.Errorf(
"failed to start node %s with given ports. probably another avalanchego process is running",
nodeConfigs[i].Name,
)
}
}
}
Expand Down

0 comments on commit a0946c5

Please sign in to comment.