Skip to content

Infinite loop in ping() when generating unique random SEED_ID #103

@cveilleux

Description

@cveilleux

If an unhandled exception occurs while performing the network call, the random seed id is not cleaned up from the shared SEED_IDs list.

Relevant code:

    # Fix to allow for pythonping multithreaded usage;
    # no need to protect this loop as no one will ever surpass 0xFFFF amount of threads
    while True:
        # seed_id needs to be less than or equal to 65535 (as original code was seed_id = getpid() & 0xFFFF)
        seed_id = randint(0x1, 0xFFFF)
        if seed_id not in SEED_IDs:
            SEED_IDs.append(seed_id)
            break

    comm = executor.Communicator(target, provider, timeout, interval, socket_options=options, verbose=verbose, output=out,
                                 seed_id=seed_id, source=source, repr_format=out_format)

    comm.run(match_payloads=match)

    SEED_IDs.remove(seed_id)

Since there are no try/finally block, the random seed_id stays in the list. Eventually the thread gets stuck at 100% cpu trying to find a free seed_id.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions