Zebra: Add a hint to the port conflict panic

Created on 9 Dec 2020  路  2Comments  路  Source: ZcashFoundation/zebra

Analysis

The port conflict panic message is hard to understand, we should add a hint about changing the default port.

This change should be made with #1509, because they need similar hints.

Version

v1.0.0-alpha.0

Platform

Unknown

Description

it is syncing, after changing the default listen address

if you have zcashd occupying 8233 it just panics with zebra_network::peer::connection: e=buffered service failed: buffered service failed: Address already in use (os error 98)

A-rust C-bug

Most helpful comment

We need to find out if the port we are going to bind is already in use. The sooner we do it is better as this is a fatal condition. Right now, the failure we see is deeply inside zebra-network. I think we should check and exit long before, somewhere around https://github.com/ZcashFoundation/zebra/blob/main/zebrad/src/commands/start.rs#L46

Next, how to do the check. I am unsure if there is an easy way with what we currently have. One option will be to add a new dependency: https://docs.rs/port_scanner/0.1.5/port_scanner/fn.local_port_available.html

Looking for advice. Thanks!

Unfortunately, there's no reliable cross-platform way to check if a port is already in use. That's because different operating systems have different rules for port conflicts. And some OSes allow programs to open ports that never conflict.

We should also avoid trying to open the port early, closing it, then opening it for real. Because that can lead to a temporary failure due to the TCP retransmit interval.

So the best way to handle this error is to try to use the port in zebra-network, and provide a helpful message if using the port fails.

If we wanted that message to happen earlier, we could try to open the listener port early in zebrad's start function, and then pass the open port to zebra-network. But I don't think that's a good design, because the port opening code belongs in zebra-network:
https://github.com/ZcashFoundation/zebra/blob/main/zebrad/src/commands/start.rs#L43

All 2 comments

We need to find out if the port we are going to bind is already in use. The sooner we do it is better as this is a fatal condition. Right now, the failure we see is deeply inside zebra-network. I think we should check and exit long before, somewhere around https://github.com/ZcashFoundation/zebra/blob/main/zebrad/src/commands/start.rs#L46

Next, how to do the check. I am unsure if there is an easy way with what we currently have. One option will be to add a new dependency: https://docs.rs/port_scanner/0.1.5/port_scanner/fn.local_port_available.html

Looking for advice. Thanks!

We need to find out if the port we are going to bind is already in use. The sooner we do it is better as this is a fatal condition. Right now, the failure we see is deeply inside zebra-network. I think we should check and exit long before, somewhere around https://github.com/ZcashFoundation/zebra/blob/main/zebrad/src/commands/start.rs#L46

Next, how to do the check. I am unsure if there is an easy way with what we currently have. One option will be to add a new dependency: https://docs.rs/port_scanner/0.1.5/port_scanner/fn.local_port_available.html

Looking for advice. Thanks!

Unfortunately, there's no reliable cross-platform way to check if a port is already in use. That's because different operating systems have different rules for port conflicts. And some OSes allow programs to open ports that never conflict.

We should also avoid trying to open the port early, closing it, then opening it for real. Because that can lead to a temporary failure due to the TCP retransmit interval.

So the best way to handle this error is to try to use the port in zebra-network, and provide a helpful message if using the port fails.

If we wanted that message to happen earlier, we could try to open the listener port early in zebrad's start function, and then pass the open port to zebra-network. But I don't think that's a good design, because the port opening code belongs in zebra-network:
https://github.com/ZcashFoundation/zebra/blob/main/zebrad/src/commands/start.rs#L43

Was this page helpful?
0 / 5 - 0 ratings

Related issues

yaahc picture yaahc  路  3Comments

hdevalence picture hdevalence  路  4Comments

dconnolly picture dconnolly  路  4Comments

yaahc picture yaahc  路  5Comments

hdevalence picture hdevalence  路  4Comments