Skip to content

Performance: Blocking traceroute and ipify calls in SocketIO event handlers #211

@techmore

Description

@techmore

Type

optimization

Severity

medium

Area

nmapui/handlers/runtime_info.py, nmapui/traceroute.py

Description

Two SocketIO event handlers perform blocking I/O that ties up the event loop:

  1. get_network_key_event calls run_traceroute("1.1.1.1") synchronously. Traceroute can take 30-60 seconds, blocking all other events for that client during execution.

  2. get_local_ip calls requests.get("https://api.ipify.org", timeout=3) synchronously. While the 3-second timeout limits worst-case, it still blocks the handler.

If multiple clients request network key simultaneously, requests serialize and compound the delay.

Proposed Fix

Run traceroute in a background task:

@socketio.on("get_network_key")
@require_socket_auth()
def get_network_key_event():
    socketio.start_background_task(
        _run_traceroute_and_emit, request.sid
    )

Cache the public IP result with a TTL (e.g., 5 minutes) to avoid repeated external calls.

Related Issues

None

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions