zed-industries/zed · error · anyhow::Error

OAuth callback port remained in use after attempts

Error message

OAuth callback port {addr} remained in use after {BIND_MAX_ATTEMPTS} attempts

What it means

Exhaustion error in try_bind_with_cancel: after BIND_MAX_ATTEMPTS (with cancel requests and BIND_RETRY_DELAY between tries) the OAuth callback port was still occupied, so the last bind error is returned and the server cannot start.

Solutions

  1. Find and terminate the stale process holding the port (e.g. leftover Zed/localhost listener)
  2. Wait a moment and retry the sign-in
  3. Use a different port via the callback server config
Defensive patterns

Strategy: retry

When it happens

Trigger: Thrown at crates/oauth_callback_server/src/oauth_callback_server.rs:452 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of zed-industries/zed@f4178619ac (2026-08-20). Data as JSON: /api/errors/56e6e951487aed38. Report an issue: GitHub.

Appendix: source

Thrown at crates/oauth_callback_server/src/oauth_callback_server.rs:452

                    if !cancel_attempted {
                        cancel_attempted = true;
                        if let Err(cancel_err) = send_cancel_request(host, port) {
                            log::warn!(
                                "Failed to cancel previous OAuth callback server on {addr}: {cancel_err}"
                            );
                        }
                    }

                    last_err = Some(anyhow!(err));
                    std::thread::sleep(BIND_RETRY_DELAY);
                }
            }
        }

        Err(last_err
            .unwrap_or_else(|| anyhow!("unknown bind error"))
            .context(format!(
                "OAuth callback port {addr} remained in use after {BIND_MAX_ATTEMPTS} attempts"
            )))
    }

    /// Sends `GET /cancel` to a listener on `host:port`, asking it to shut down.
    ///
    /// Best-effort: errors here are surfaced to the caller for logging but do
    /// not block the subsequent rebind attempt.
    fn send_cancel_request(host: &str, port: u16) -> std::io::Result<()> {
        use std::io::{Read as _, Write as _};
        use std::net::{TcpStream, ToSocketAddrs as _};

        let addr = format!("{host}:{port}")
            .to_socket_addrs()?
            .next()
            .ok_or_else(|| {
                std::io::Error::new(
                    std::io::ErrorKind::InvalidInput,
                    format!("could not resolve {host}:{port}"),

View on GitHub (pinned to f4178619ac)