|
After taking a first pass at digging into this, it's hard to say if the SMF provider is doing the right thing or not.
First, some background on SMF service states. Every service on the system has a state and an nstate. State represents the current state of the service, while nstate represents the next state and is only used when a service is transitioning between states. For example, while puppet is happily running, we see:
-bash-3.2# svcs -H -o state,nstate puppet
|
online - # <== the '-' indicates that there is no state transition happening.
|
The SMF provider uses both the state and nstate to determine the "status" of the service. The following is the block of logic in question:
84 # get the current state and the next state, and if the next
|
85 # state is set (i.e. not "-") use it for state comparison
|
86 states = svcs("-H", "-o", "state,nstate", @resource[:name]).chomp.split
|
87 state = states[1] == "-" ? states[0] : states[1]
|
...
|
93 case state
|
94 when "online"
|
95 #self.warning "matched running #{line.inspect}"
|
96 return :running
|
97 when "offline", "disabled", "uninitialized"
|
98 #self.warning "matched stopped #{line.inspect}"
|
99 return :stopped
|
...
|
So, if no state transition is happening, we use state as the indicator of service state. If the service is transitioning, we use nstate. This results in our race condition due to the following conditions:
Restarting the puppet service
When the puppet service is restarted, we see the following state s and nstate s in realtime:
-bash-3.2# svcs -H -o state,nstate puppet
|
online - # <=== Before the restart
|
...
|
-bash-3.2# svcs -H -o state,nstate puppet
|
online offline # <=== During the restart, when the current state is 'online' and the next (transitional) state is 'offline'
|
-bash-3.2# svcs -H -o state,nstate puppet
|
online offline
|
-bash-3.2# svcs -H -o state,nstate puppet
|
online offline
|
...
|
-bash-3.2# svcs -H -o state,nstate puppet
|
offline online # <=== During the restart, when the current state is 'offline' and the next (transitional) state is 'online'
|
-bash-3.2# svcs -H -o state,nstate puppet
|
offline online
|
-bash-3.2# svcs -H -o state,nstate puppet
|
offline online
|
-bash-3.2# svcs -H -o state,nstate puppet
|
online - # <=== When the restart has finished, and puppet is running again.
|
|
So essentially, puppet currently deals with the dual transitional states by assuming that the next state is the actual state, this causing our race condition.
|