erigontech / silkworm

C++ implementation of the Ethereum protocol
Apache License 2.0
272 stars 63 forks source link

Improve the error message: Address already in use #1398

Open battlmonstr opened 11 months ago

battlmonstr commented 11 months ago

When starting silkworm without arguments after staring erigon without arguments on the same computer, silkworm crashes with "Unrecoverable failure: Address already in use" and no other clues. Apparently it wants to occupy some default TCP/UDP ports that are in use by the erigon process.

The error message needs to be improved to explain what port is occupied, what for is it needed, and which command line parameter must be passed to customize it.

battlmonstr commented 5 months ago

PR 1: https://github.com/erigontech/silkworm/pull/1611 PR 2: https://github.com/erigontech/silkworm/pull/1788

battlmonstr commented 5 months ago

One place where this still happens is in the sentry GRPC servers. In this case BuildAndStart returns null here: https://github.com/erigontech/silkworm/blob/master/silkworm/infra/grpc/server/server.hpp#L84

It is possible to implement GlobalCallbacks::AddPort, and call grpc::Server::SetGlobalCallbacks(...) to register the implementation. BuildAndStart() calls it here and that should trigger a callback. If port == 0 in the AddPort callback, we can assume that the port is busy.

This gives information to extend the error message here: https://github.com/erigontech/silkworm/blob/master/silkworm/infra/grpc/server/server.hpp#L86