1
1
use crate :: inspector_server:: Inspector ;
2
- use crate :: rt_worker:: rt;
3
2
use crate :: rt_worker:: supervisor:: { CPUUsage , CPUUsageMetrics } ;
4
3
use crate :: rt_worker:: worker:: DuplexStreamEntry ;
5
4
use crate :: utils:: units:: { bytes_to_display, mib_to_bytes} ;
@@ -25,6 +24,7 @@ use futures_util::future::poll_fn;
25
24
use futures_util:: task:: AtomicWaker ;
26
25
use log:: { error, trace} ;
27
26
use once_cell:: sync:: { Lazy , OnceCell } ;
27
+ use sb_core:: conn_sync:: DenoRuntimeDropToken ;
28
28
use sb_core:: http:: sb_core_http;
29
29
use sb_core:: http_start:: sb_core_http_start;
30
30
use sb_core:: util:: sync:: AtomicFlag ;
@@ -184,6 +184,7 @@ impl GetRuntimeContext for () {
184
184
}
185
185
186
186
pub struct DenoRuntime < RuntimeContext = ( ) > {
187
+ pub drop_token : CancellationToken ,
187
188
pub js_runtime : JsRuntime ,
188
189
pub env_vars : HashMap < String , String > , // TODO: does this need to be pub?
189
190
pub conf : WorkerRuntimeOpts ,
@@ -203,6 +204,8 @@ pub struct DenoRuntime<RuntimeContext = ()> {
203
204
204
205
impl < RuntimeContext > Drop for DenoRuntime < RuntimeContext > {
205
206
fn drop ( & mut self ) {
207
+ self . drop_token . cancel ( ) ;
208
+
206
209
if self . conf . is_user_worker ( ) {
207
210
self . js_runtime . v8_isolate ( ) . remove_gc_prologue_callback (
208
211
mem_check_gc_prologue_callback_fn,
@@ -238,13 +241,16 @@ where
238
241
..
239
242
} = opts;
240
243
244
+ let drop_token = CancellationToken :: default ( ) ;
245
+
241
246
let base_dir_path = std:: env:: current_dir ( ) . map ( |p| p. join ( & service_path) ) ?;
242
247
let base_url = Url :: from_directory_path ( & base_dir_path) . unwrap ( ) ;
243
248
244
249
let is_user_worker = conf. is_user_worker ( ) ;
245
250
246
251
let potential_exts = vec ! [ "ts" , "tsx" , "js" , "jsx" ] ;
247
252
let mut main_module_url = base_url. join ( "index.ts" ) ?;
253
+
248
254
for potential_ext in potential_exts {
249
255
main_module_url = base_url. join ( format ! ( "index.{}" , potential_ext) . as_str ( ) ) ?;
250
256
if main_module_url. to_file_path ( ) . unwrap ( ) . exists ( ) {
@@ -587,6 +593,7 @@ where
587
593
}
588
594
589
595
op_state. put :: < sb_env:: EnvVars > ( env_vars) ;
596
+ op_state. put ( DenoRuntimeDropToken ( drop_token. clone ( ) ) )
590
597
}
591
598
592
599
let main_module_id = {
@@ -600,7 +607,7 @@ where
600
607
} ;
601
608
602
609
if is_user_worker {
603
- drop ( rt :: SUPERVISOR_RT . spawn ( {
610
+ drop ( base_rt :: SUPERVISOR_RT . spawn ( {
604
611
let drop_token = mem_check. drop_token . clone ( ) ;
605
612
let waker = mem_check. waker . clone ( ) ;
606
613
@@ -624,6 +631,7 @@ where
624
631
}
625
632
626
633
Ok ( Self {
634
+ drop_token,
627
635
js_runtime,
628
636
env_vars,
629
637
conf,
@@ -866,7 +874,7 @@ where
866
874
let drop_token = self . mem_check . drop_token . clone ( ) ;
867
875
let state = self . mem_check_state ( ) ;
868
876
869
- drop ( rt :: SUPERVISOR_RT . spawn ( async move {
877
+ drop ( base_rt :: SUPERVISOR_RT . spawn ( async move {
870
878
loop {
871
879
tokio:: select! {
872
880
_ = notify. notified( ) => {
0 commit comments