You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Serializes lifecycle transitions such as start, restart and reload. `Container#stop` (which can also take time) is performed outside this guard, so that live container events are not blocked by the stop operation (e.g. restarting).
69
70
@guard= ::Thread::Mutex.new
@@ -117,7 +118,7 @@ def trap(signal, &block)
117
118
event=SignalEvent.new(signal,block).freeze
118
119
119
120
@signals.trap(signal)do
120
-
@events << event
121
+
enqueue_event(event)
121
122
end
122
123
else
123
124
@signals.ignore(signal)
@@ -272,12 +273,44 @@ def reload
272
273
end
273
274
end
274
275
275
-
privatedefwait_for_container
276
+
privatedefenqueue_event(event)
277
+
@events << event
278
+
rescue ::ClosedQueueError
279
+
# The controller run loop has already stopped.
280
+
end
281
+
282
+
privatedefopen_event_queue
283
+
@guard.synchronizedo
284
+
if@running
285
+
raiseRuntimeError,"Controller is already running."
286
+
end
287
+
288
+
@running=true
289
+
@events= ::Thread::Queue.new
290
+
end
291
+
end
292
+
293
+
privatedefclose_event_queue(events)
294
+
events.close
295
+
end
296
+
297
+
privatedeffinish_event_queue(events)
298
+
events.close
299
+
300
+
@guard.synchronizedo
301
+
if@events.equal?(events)
302
+
@running=false
303
+
@events= ::Thread::Queue.new
304
+
end
305
+
end
306
+
end
307
+
308
+
privatedefwait_for_container(events)
276
309
whiletrue
277
310
container=@guard.synchronize{@container}
278
311
279
312
ifcontainer.nil?
280
-
@events.close
313
+
close_event_queue(events)
281
314
return
282
315
end
283
316
@@ -287,7 +320,7 @@ def reload
287
320
# If this is still the active container, it completed naturally. Clear it and close the event queue so the controller run loop can finish. If it was replaced by a restart, keep waiting for the new active container.
288
321
if@container.equal?(container)
289
322
@container=nil
290
-
@events.close
323
+
close_event_queue(events)
291
324
return
292
325
end
293
326
end
@@ -298,14 +331,15 @@ def reload
298
331
# @parameter signals [#install] The signal backend to use while running the controller.
0 commit comments