[En-Nut-Discussion] Possible race condition in DHCP and DHCPKick

Henrik Maier hmnews at proconx.com
Fri Feb 10 06:39:44 CET 2012


Hi all,

it appears that there is a race condition in DHCP, routine DhcpKick():

I observed cases where the following sequence would cause a system 
lock-up because the NutEventWait/dhcpDone condition is never fullfilled. 
Some debugging and analysis of the order of events sent and received 
between the caller and DHCP thread shows, that there are cases where 
NutEventPost does a context switch and the dhcpDone event is sent 
before(!) NutEventWait(&dhcpDone) is called resulting the subsequent 
call of NutEventWait(&dhcpDone) to never return.

	...
	NutEventPost(&dhcpWake);
	NutEventWait(&dhcpDone, NUT_WAIT_INFINITE);
	...

The issue seems to be fixed once above NutEventPost is changed to a 
NutEventPostAsync which avoids the context switch before NutEventWait is 
called:

	...
	NutEventPostAsync(&dhcpWake);
	NutEventWait(&dhcpDone, NUT_WAIT_INFINITE);
	...

If there are no objections or further insight into this topic, I would 
submit a bug report to tracker and a patch.

I think in most applications DhcpKick is only called once during system 
start and the issue does not come up. But if a system changes from DHCP 
to statically allocated IP addresses or vice versa, DhcpKick is called 
on every change and the issue comes to surface.


Regards

Henrik Maier



More information about the En-Nut-Discussion mailing list