@@ -43,6 +43,21 @@ pub async fn supervise(args: Arguments) -> ShutdownReason {
43
43
. unwrap_or ( Duration :: from_millis ( 0 ) ) ,
44
44
) ;
45
45
46
+ let interrupt_fn = {
47
+ let thread_safe_handle = thread_safe_handle. clone ( ) ;
48
+ move |should_terminate : bool | {
49
+ let interrupt_data = IsolateInterruptData {
50
+ should_terminate,
51
+ isolate_memory_usage_tx,
52
+ } ;
53
+
54
+ thread_safe_handle. request_interrupt (
55
+ handle_interrupt,
56
+ Box :: into_raw ( Box :: new ( interrupt_data) ) as * mut std:: ffi:: c_void ,
57
+ ) ;
58
+ }
59
+ } ;
60
+
46
61
tokio:: pin!( wall_clock_duration_alert) ;
47
62
48
63
loop {
@@ -55,22 +70,13 @@ pub async fn supervise(args: Arguments) -> ShutdownReason {
55
70
cpu_time_soft_limit_reached = true ;
56
71
57
72
if req_ack_count == demand. load( Ordering :: Acquire ) {
58
- let interrupt_data = IsolateInterruptData {
59
- should_terminate: true ,
60
- isolate_memory_usage_tx
61
- } ;
62
-
63
- thread_safe_handle. request_interrupt( handle_interrupt, Box :: into_raw( Box :: new( interrupt_data) ) as * mut std:: ffi:: c_void) ;
73
+ interrupt_fn( true ) ;
64
74
error!( "early termination due to the last request being completed. isolate: {:?}" , key) ;
65
75
return ShutdownReason :: EarlyDrop ;
66
76
}
67
77
} else {
68
78
// shutdown worker
69
- let interrupt_data = IsolateInterruptData {
70
- should_terminate: true ,
71
- isolate_memory_usage_tx
72
- } ;
73
- thread_safe_handle. request_interrupt( handle_interrupt, Box :: into_raw( Box :: new( interrupt_data) ) as * mut std:: ffi:: c_void) ;
79
+ interrupt_fn( true ) ;
74
80
error!( "CPU time hard limit reached. isolate: {:?}" , key) ;
75
81
return ShutdownReason :: CPUTime ;
76
82
}
@@ -91,12 +97,7 @@ pub async fn supervise(args: Arguments) -> ShutdownReason {
91
97
continue ;
92
98
}
93
99
94
- let interrupt_data = IsolateInterruptData {
95
- should_terminate: true ,
96
- isolate_memory_usage_tx
97
- } ;
98
-
99
- thread_safe_handle. request_interrupt( handle_interrupt, Box :: into_raw( Box :: new( interrupt_data) ) as * mut std:: ffi:: c_void) ;
100
+ interrupt_fn( true ) ;
100
101
error!( "early termination due to the last request being completed. isolate: {:?}" , key) ;
101
102
return ShutdownReason :: EarlyDrop ;
102
103
}
@@ -115,27 +116,21 @@ pub async fn supervise(args: Arguments) -> ShutdownReason {
115
116
// wall-clock limit reached
116
117
// Don't terminate isolate from supervisor when wall-clock
117
118
// duration reached. It's dropped in deno_runtime.rs
118
- let interrupt_data = IsolateInterruptData {
119
+ interrupt_fn (
119
120
// NOTE: Wall clock is also triggered when no more
120
121
// pending requests, so we must compare the request
121
122
// count here to judge whether we need to terminate the
122
123
// isolate.
123
- should_terminate: req_ack_count == demand. load( Ordering :: Acquire ) ,
124
- isolate_memory_usage_tx
125
- } ;
126
- thread_safe_handle. request_interrupt( handle_interrupt, Box :: into_raw( Box :: new( interrupt_data) ) as * mut std:: ffi:: c_void) ;
127
- error!( "wall clock duration reached. isolate: {:?}" , key) ;
124
+ req_ack_count == demand. load( Ordering :: Acquire ) ,
125
+ ) ;
126
+
128
127
return ShutdownReason :: WallClockTime ;
129
128
}
130
129
}
131
130
132
131
// memory usage
133
132
Some ( _) = memory_limit_rx. recv( ) => {
134
- let interrupt_data = IsolateInterruptData {
135
- should_terminate: true ,
136
- isolate_memory_usage_tx
137
- } ;
138
- thread_safe_handle. request_interrupt( handle_interrupt, Box :: into_raw( Box :: new( interrupt_data) ) as * mut std:: ffi:: c_void) ;
133
+ interrupt_fn( true ) ;
139
134
error!( "memory limit reached for the worker. isolate: {:?}" , key) ;
140
135
return ShutdownReason :: Memory ;
141
136
}
0 commit comments