Shadowsocks-libev: when using domain as server address, ss-libev would directly exit if the domain cannot be resolved

Created on 5 Mar 2015  ·  6Comments  ·  Source: shadowsocks/shadowsocks-libev

For example, if I wrote

{
    "server":"example.com",
    ......
}

and if my network is not available (e.g., when booting), ss-server will directly exit with 255 and output

 2015-03-05 11:25:19 ERROR: getaddrinfo: Temporary failure in name resolution
 2015-03-05 11:25:19 ERROR: failed to resolve the provided hostname

I wish it shadowsocks would retry to resolve the domain until the network becomes available.

Most helpful comment

I recently encountered this issue on Arch Linux. The shadowsocks-libev systemd unit is started very first and network-online.target hasn't been pulled in. Using domain instead of IP address results in the error below:

Mar 17 18:01:31 perqin-nuc ss-local[485]:  2019-03-17 18:01:31 ERROR: getaddrinfo: Temporary failure in name resolution
Mar 17 18:01:31 perqin-nuc ss-local[485]:  2019-03-17 18:01:31 ERROR: failed to resolve the provided hostname
Mar 17 18:01:31 perqin-nuc systemd[1]: [email protected]: Main process exited, code=exited, status=255/EXCEPTION
Mar 17 18:01:31 perqin-nuc systemd[1]: [email protected]: Failed with result 'exit-code'.

Modifying /usr/lib/systemd/system/[email protected] and adding Wants after After works well:

[Unit]
Description=Shadowsocks-Libev Client Service
After=network-online.target
# Add the line below
Wants=network-online.target

[Service]
Type=simple
User=nobody
CapabilityBoundingSet=CAP_NET_BIND_SERVICE
ExecStart=/usr/bin/ss-local -c /etc/shadowsocks/%i.json

[Install]
WantedBy=multi-user.target

Tested on Arch Linux with latest shadowsocks-libev and NetworkManager packages installed.

All 6 comments

BTW, the python version of shadowsocks works under this situation.

  1. Use IP address instead.
  2. Test the network before start shadowsocks.

Is there any good reason not to retry when the first domain resolution fails?

The reason I do not use IP address is that my server contain both IPv4 and IPv6 address. I want to make shadowsocks use IPv6 if ipv6 network is available and otherwise use ipv4. Using IP address will lose this function.

The problem is that I want to start shadowsocks as a system daemon (in systemd), so it is not convenient for me to test the network before start shadowsocks. Although I can make systemd restart for me, it is not an elegant solution for me.

I recently encountered this issue on Arch Linux. The shadowsocks-libev systemd unit is started very first and network-online.target hasn't been pulled in. Using domain instead of IP address results in the error below:

Mar 17 18:01:31 perqin-nuc ss-local[485]:  2019-03-17 18:01:31 ERROR: getaddrinfo: Temporary failure in name resolution
Mar 17 18:01:31 perqin-nuc ss-local[485]:  2019-03-17 18:01:31 ERROR: failed to resolve the provided hostname
Mar 17 18:01:31 perqin-nuc systemd[1]: [email protected]: Main process exited, code=exited, status=255/EXCEPTION
Mar 17 18:01:31 perqin-nuc systemd[1]: [email protected]: Failed with result 'exit-code'.

Modifying /usr/lib/systemd/system/[email protected] and adding Wants after After works well:

[Unit]
Description=Shadowsocks-Libev Client Service
After=network-online.target
# Add the line below
Wants=network-online.target

[Service]
Type=simple
User=nobody
CapabilityBoundingSet=CAP_NET_BIND_SERVICE
ExecStart=/usr/bin/ss-local -c /etc/shadowsocks/%i.json

[Install]
WantedBy=multi-user.target

Tested on Arch Linux with latest shadowsocks-libev and NetworkManager packages installed.

@perqin If I remember correctly the “modern” version of shadowsocks-libev uses gethostbyname() (or getaddrinfo() as can be seen from the error message?) for domain resolution. So if it says “failure in domain resolution” it basically means either

  • DNS server is unreachable (check internet connectivity)

OR

  • the domain requested does NOT exist on servers specified in /etc/resolv.conf. (please double check the domain name you entered for spelling mistakes)

@PantherJohn It uses getaddrinfo(). The failure only happens during boot, and once I restart the service after having access to the terminal, it works properly. I am going to check the /etc/resolv.conf at failure some time later, but I think the issue is caused by no internet connection (because it starts before network-online.target is reached, as I mentioned before).

Was this page helpful?
0 / 5 - 0 ratings