ofproto-dpif-upcall: Fix a race.
authorAlex Wang <alexw@nicira.com>
Tue, 25 Mar 2014 20:57:25 +0000 (13:57 -0700)
committerAlex Wang <alexw@nicira.com>
Fri, 28 Mar 2014 16:19:47 +0000 (09:19 -0700)
commit5878877a75a11d9e73f61cebfa18ff84dcdd64ba
tree4d56486e92f75464cf79c90f48ed3877d8596d2f
parentc3ccfe984933ca8df56d551cb3ae7e0bf3d119b8
ofproto-dpif-upcall: Fix a race.

Commit 61057e884ca9c(ofproto-dpif-upcall: Slightly simplify
udpif_upcall_handler().) restructured the main loop in
udpif_upcall_handler() and discarded the check for the
'exit_latch' after acquiring the mutex.  This makes it
possible for the following race:

- main thread sets the 'exit_latch' after the handler thread
  checking it.
- main thread acquires the handler thread mutex and signals the
  condition variable of handler thread.
- main thread releases the mutex and 'join' the handler thread.
- handler thread acquires the mutex, finds that n_upcalls is 0
  and waits on the signal of condition variable.
- then OVS will hang forever.

This commit fixes the above issue by adding a check for the
'exit_latch' after acquiring the mutex.

Bug #1217229

Signed-off-by: Alex Wang <alexw@nicira.com>
Acked-by: Ethan Jackson <ethan@nicira.com>
ofproto/ofproto-dpif-upcall.c