pythonping icon indicating copy to clipboard operation
pythonping copied to clipboard

Infinite loop in ping() when generating unique random SEED_ID

Open cveilleux opened this issue 1 year ago • 0 comments

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.

cveilleux avatar Mar 24 '23 15:03 cveilleux