File tree Expand file tree Collapse file tree 4 files changed +62
-9
lines changed Expand file tree Collapse file tree 4 files changed +62
-9
lines changed Original file line number Diff line number Diff line change @@ -51,6 +51,9 @@ def execute(ct)
51
51
# in low memory situations.
52
52
ct . cgparams . temporarily_expand_memory if ct . running?
53
53
54
+ run_conf = ct . get_run_conf
55
+ promise = run_conf . get_exit_promise if run_conf . init_pid
56
+
54
57
begin
55
58
DistConfig . run (
56
59
ct . get_run_conf ,
@@ -71,6 +74,10 @@ def execute(ct)
71
74
error! ( e . message )
72
75
end
73
76
77
+ if promise && promise . wait . nil?
78
+ log ( :warn , "Timeout while waiting for exit promise of #{ ct . ident } " )
79
+ end
80
+
74
81
remove_accounting_cgroups ( ct )
75
82
76
83
if ct . ephemeral? && !indirect?
Original file line number Diff line number Diff line change @@ -75,15 +75,10 @@ def on_ct_stop
75
75
)
76
76
end
77
77
78
- if ctrc . aborted? \
79
- || ctrc . reboot? \
80
- || ( ct . ephemeral? && !ct . is_being_manipulated? ) \
81
- || ctrc . destroy_dataset_on_stop?
82
- # The current thread is used to handle the console and has to exit.
83
- # Manipulation must happen from another thread.
84
- t = Thread . new { handle_ct_stop ( ctrc ) }
85
- ThreadReaper . add ( t , nil )
86
- end
78
+ # The current thread is used to handle the console and has to exit.
79
+ # Manipulation must happen from another thread.
80
+ t = Thread . new { handle_ct_stop ( ctrc ) }
81
+ ThreadReaper . add ( t , nil )
87
82
88
83
ct . forget_past_run_conf
89
84
end
@@ -105,6 +100,8 @@ def handle_ct_stop(ctrc)
105
100
GarbageCollector . free_container_run_dataset ( ctrc , ctrc . dataset )
106
101
end
107
102
103
+ ctrc . fulfil_exit
104
+
108
105
if ctrc . reboot?
109
106
sleep ( 1 )
110
107
reboot_ct
Original file line number Diff line number Diff line change @@ -35,6 +35,7 @@ def initialize(ct, load_conf: true)
35
35
@init_pid = nil
36
36
@aborted = false
37
37
@do_reboot = false
38
+ @exit_promise = Promise . new
38
39
@dist_network_configured = false
39
40
self . load_conf ( from_file : load_conf )
40
41
end
@@ -149,6 +150,14 @@ def reboot?
149
150
@do_reboot
150
151
end
151
152
153
+ def get_exit_promise
154
+ @exit_promise . add
155
+ end
156
+
157
+ def fulfil_exit
158
+ @exit_promise . fulfil
159
+ end
160
+
152
161
def dist_configure_network?
153
162
inclusively do
154
163
!dist_network_configured && can_dist_configure_network?
Original file line number Diff line number Diff line change
1
+ require 'libosctl'
2
+
3
+ module OsCtld
4
+ class Promise
5
+ class Token
6
+ def initialize
7
+ @queue = OsCtl ::Lib ::Queue . new
8
+ end
9
+
10
+ # Wait until the promise is fulfilled
11
+ # @param timeout [Integer]
12
+ # @return [true, nil]
13
+ def wait ( timeout : 60 )
14
+ @queue . pop ( timeout :)
15
+ end
16
+
17
+ # Fulfil the promise
18
+ def fulfil
19
+ @queue << true
20
+ end
21
+ end
22
+
23
+ def initialize
24
+ @mutex = Mutex . new
25
+ @tokens = [ ]
26
+ end
27
+
28
+ # @return [Token]
29
+ def add
30
+ t = Token . new
31
+ @tokens << t
32
+ t
33
+ end
34
+
35
+ def fulfil
36
+ @tokens . each ( &:fulfil )
37
+ nil
38
+ end
39
+ end
40
+ end
You can’t perform that action at this time.
0 commit comments