axel-download-accelerator / axel

Lightweight CLI download accelerator
GNU General Public License v2.0
2.84k stars 258 forks source link

Attempting to join an already joined thread at axel.c #411

Open hcantunc opened 8 months ago

hcantunc commented 8 months ago

Hello,

My bug detector tool found a concurrency issue in axel version 2.17.11, where a thread that has already been joined is attempted to be joined again. Below please find the detailed report.

At axel.c line 672 the first join occurs.

...
if (axel_gettime() > (axel->conn[i].last_transfer +
            axel->conf->reconnect_delay)) {
    pthread_cancel(*axel->conn[i].setup_thread);
    axel->conn[i].state = false;
    pthread_join(*axel->conn[i].
                setup_thread, NULL);
}

However, in axel.c line 643, it is still possible to call the pthread_join on the same thread that was joined before.

...
if (!axel->conn[i].state) {
    // Wait for termination of this thread
    pthread_join(*(axel->conn[i].setup_thread),
                NULL);
}

This behavior is non-deterministic and is not always present. However, I can reproduce this behavior deterministically by putting a short sleep statement before the lock acquire event in axel.c line 835. I presumed that this is not an intended behavior. Would you be able to confirm the validity of this issue?

Thank you.