cherokee / webserver

Cherokee Web Server
GNU General Public License v2.0
568 stars 104 forks source link

A locking issue in cherokee_server_free #1278

Open ryancaicse opened 2 years ago

ryancaicse commented 2 years ago

Hi, there is only an unlocking in the loop, should it be a bug? https://github.com/cherokee/webserver/blob/5b1dbdb4dd68872014874ac05f8af0f833343d0f/cherokee/server.c#L266-L269

skinkie commented 2 years ago

It may be, at this point I don't understand the code here. Did this produce a hang or crash at your side?

ryancaicse commented 2 years ago

Hi, I guess, the lock is supposed to protect the THREAD(i)->exit = true; from races. May be there is a missing CHEROKEE_MUTEX_LOCK.

skinkie commented 2 years ago

I just looked through the code (thread.c) to see what is is used for there. But I wonder if this is actually the way to unlock what has been locked there.

ryancaicse commented 2 years ago

@skinkie It seems, in this loop, an identical lock is released multiple times rather than releasing different indexed locks. Thus, it is very likely a bug.

I also tried to investigate the reason. However, I could not find the possible held lock at that program point. I think it is more likely that the lock is supposed to protect the THREAD(i)->exit = true; from races and there is a missing CHEROKEE_MUTEX_LOCK.