Skip to content

Just Enabling Debug Toolbar as Middleware creates Delays of Several Seconds on each request #1927

Closed
@QBH3

Description

@QBH3

in debug_toolbar/middleware.py is following code:

def show_toolbar(request):
    """
    Default function to determine whether to show the toolbar on a given page.
    """
    internal_ips = list(settings.INTERNAL_IPS)

    try:
        # This is a hack for docker installations. It attempts to look
        # up the IP address of the docker host.
        # This is not guaranteed to work.
        docker_ip = (
            # Convert the last segment of the IP address to be .1
            ".".join(socket.gethostbyname("host.docker.internal").rsplit(".")[:-1])
            + ".1"
        )
        internal_ips.append(docker_ip)
    except socket.gaierror:
        # It's fine if the lookup errored since they may not be using docker
        pass
    return settings.DEBUG and request.META.get("REMOTE_ADDR") in internal_ips

on every request it tries to resolve host.docker.internal which might lead to a timeout from the resolver running locally.

I believe at least this behaviour should be described in the documentation and that it might cause problems with certain resolvers.

Also I believe it should be sufficient to do this name resolution only once per server startup and not at every request.

Another way might be to use the documentation to decribe how to add host.docker.internal to INTERNAL_IPS if a user is inclined to do so.

What do you think?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions