File tree 1 file changed +26
-2
lines changed
src/platform/backends/shared 1 file changed +26
-2
lines changed Original file line number Diff line number Diff line change @@ -113,8 +113,32 @@ void BaseAvailabilityZone::set_available(const bool new_available)
113
113
m.available = new_available;
114
114
serialize ();
115
115
116
- for (auto & vm : m.vms )
117
- vm.get ().set_available (m.available );
116
+ try
117
+ {
118
+ for (auto & vm : m.vms )
119
+ vm.get ().set_available (new_available);
120
+ }
121
+ catch (...)
122
+ {
123
+ // if an error occurs fallback to available.
124
+ m.available = true ;
125
+ serialize ();
126
+
127
+ // make sure nothing is still unavailable.
128
+ for (auto & vm : m.vms )
129
+ {
130
+ // setting the state here breaks encapsulation, but it's already broken.
131
+ std::unique_lock vm_lock{vm.get ().state_mutex };
132
+ if (vm.get ().current_state () == VirtualMachine::State::unavailable)
133
+ {
134
+ vm.get ().state = VirtualMachine::State::off;
135
+ vm.get ().update_state ();
136
+ }
137
+ }
138
+
139
+ // rethrow the error so something else can deal with it.
140
+ throw ;
141
+ }
118
142
}
119
143
120
144
void BaseAvailabilityZone::add_vm (VirtualMachine& vm)
You can’t perform that action at this time.
0 commit comments