HelloZeroNet/ZeroNet · error · Exception

Can't find bindable port

Error message

Can't find bindable port

What it means

Startup failure in FileServer.__init__ port selection: when config requires the Tor hidden-service port or a random port, the code iterates the configured port range and this error fires when every candidate port fails to bind (all occupied or forbidden), so the file server cannot start listening at all.

Source

Thrown at src/File/FileServer.py:49

        self.supported_ip_types = ["ipv4"]  # Outgoing ip_type support
        if helper.getIpType(ip) == "ipv6" or self.isIpv6Supported():
            self.supported_ip_types.append("ipv6")

        if ip_type == "ipv6" or (ip_type == "dual" and "ipv6" in self.supported_ip_types):
            ip = ip.replace("*", "::")
        else:
            ip = ip.replace("*", "0.0.0.0")

        if config.tor == "always":
            port = config.tor_hs_port
            config.fileserver_port = port
        elif port == 0:  # Use random port
            port_range_from, port_range_to = list(map(int, config.fileserver_port_range.split("-")))
            port = self.getRandomPort(ip, port_range_from, port_range_to)
            config.fileserver_port = port
            if not port:
                raise Exception("Can't find bindable port")
            if not config.tor == "always":
                config.saveValue("fileserver_port", port)  # Save random port value for next restart
                config.arguments.fileserver_port = port

        ConnectionServer.__init__(self, ip, port, self.handleRequest)
        self.log.debug("Supported IP types: %s" % self.supported_ip_types)

        if ip_type == "dual" and ip == "::":
            # Also bind to ipv4 addres in dual mode
            try:
                self.log.debug("Binding proxy to %s:%s" % ("::", self.port))
                self.stream_server_proxy = StreamServer(
                    ("0.0.0.0", self.port), self.handleIncomingConnection, spawn=self.pool, backlog=100
                )
            except Exception as err:
                self.log.info("StreamServer proxy create error: %s" % Debug.formatException(err))

        self.port_opened = {}

View on GitHub (pinned to 454c0b2e7e)

Solutions

  1. Free the ports in the configured range or change config.values (fileserver_port / port range) to an open range
  2. Run with elevated privileges only if binding a privileged port, or pick a port >1024
  3. Configure tor='always' with a valid tor_hs_port if normal binding is impossible
Defensive patterns

Strategy: fallback

When it happens

Trigger: Thrown at src/File/FileServer.py:49 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of HelloZeroNet/ZeroNet@454c0b2e7e (2026-09-02). Data as JSON: /api/errors/07b33f1d531c7ef7. Report an issue: GitHub.