def handle_port(service_name: str, port: int, auto_increment: bool) -> int:
    """Change port if the specified port is in use and is not explicitly specified as a CLI arg or config arg.
    Otherwise tell the user the port is in use and exit the app.

    Args:
        service_name: The frontend or backend.
        port: The provided port.
        auto_increment: Whether to automatically increment the port.

    Returns:
        The port to run the service on.

    Raises:
        Exit:when the port is in use.
    """
    if (process := get_process_on_port(port)) is None:
        return port
    if auto_increment:
        return change_port(port, service_name)
    console.error(
        f"{service_name.capitalize()} port: {port} is already in use by PID: {process.pid}."
    )
    raise click.exceptions.Exit
Change port if the specified port is in use and is not explicitly specified as a CLI arg or config arg.
    Otherwise tell the user the port is in use and exit the app.

    Args:
        service_name: The frontend or backend.
        port: The provided port.
        auto_increment: Whether to automatically increment the port.

    Returns:
        The port to run the service on.

    Raises:
        Exit:when the port is in use.
    
reflex/utils/processes.py