How do I fix "java.net.BindException: Can't assign requested address"?

The full message looks like:

Exception in thread "main" java.net.BindException: Can't assign requested address: Service 'sparkDriver' failed after 16 retries!
Consider explicitly setting the appropriate port for the service 'sparkDriver' (for example spark.ui.port for SparkUI) to an available port or increasing spark.port.maxRetries.

This error is often caused by running spark on a machine connected to a VPN or a personal wi-fi hotspot (i.e. tethering to a phone). First, try fixing it by editing your hosts file as suggested in this StackOverflow post. If that fails, try running hail while disconnected from any VPN or personal wi-fi hotspot.

This worked for me:

sudo hostname -s 127.0.0.1

I’d note that the above is not a recommended solution – there are ways around this without changing the hostname.

First try this:

sudo /bin/sh -c "echo \"127.0.0.1 $(hostname)\" >> /etc/hostname"

Now try to use Hail. If Hail gives the same error, try this:

echo 'export PYSPARK_SUBMIT_ARGS='\''--driver-memory 16g --executor-memory 16g --conf "spark.driver.bindAddress=127.0.0.1" pyspark-shell'\' >> ~/.$(basename ${SHELL})rc

Now try Hail again. If it still fails, respond to this thread.