Skip to content

Bug: Job cancellation sends SIGTERM only — hung nmap processes never get SIGKILL #207

@techmore

Description

@techmore

Type

bug

Severity

medium

Area

nmapui/jobs.py — job cancellation logic

Description

When a scan job is cancelled, the code sends process.terminate() (SIGTERM) but never escalates to process.kill() (SIGKILL) if the process does not exit. Nmap can sometimes ignore SIGTERM (particularly during certain NSE script phases), leaving zombie processes consuming resources.

if process and process.poll() is None:
    try:
        process.terminate()
    except Exception:
        logger.exception("...")

Proposed Fix

Add a timeout-and-kill escalation:

if process and process.poll() is None:
    try:
        process.terminate()
        try:
            process.wait(timeout=5)
        except subprocess.TimeoutExpired:
            logger.warning("Process %s did not exit after SIGTERM, sending SIGKILL", process.pid)
            process.kill()
            process.wait(timeout=3)
    except Exception:
        logger.exception("Failed to terminate process")

Related Issues

#195 (Menu bar close must kill all app instances)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions