Skip to content

Commit

Permalink
fix: correctly enforce max duration
Browse files Browse the repository at this point in the history
Co-authored-by: Lakshan Perera <lakshan@laktek.com>
Co-authored-by: Mathias Lafeldt <mathias.lafeldt@gmail.com>
  • Loading branch information
laktek and mlafeldt committed Apr 17, 2023
1 parent 85699f6 commit 7171ec7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
7 changes: 4 additions & 3 deletions crates/base/src/edge_runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ impl EdgeRuntime {
&mut self,
worker_timeout_ms: u64,
mut memory_limit_rx: mpsc::UnboundedReceiver<u64>,
halt_execution_tx: oneshot::Sender<()>,
halt_isolate_tx: oneshot::Sender<()>,
) {
let thread_safe_handle = self.js_runtime.v8_isolate().thread_safe_handle();

Expand All @@ -277,7 +277,8 @@ impl EdgeRuntime {
let future = async move {
tokio::select! {
_ = tokio::time::sleep(Duration::from_millis(worker_timeout_ms)) => {
debug!("max duration reached for the worker. terminating the worker. (duration {})", human_elapsed(worker_timeout_ms))
debug!("max duration reached for the worker. terminating the worker. (duration {})", human_elapsed(worker_timeout_ms));
thread_safe_handle.terminate_execution();
}
Some(val) = memory_limit_rx.recv() => {
error!("memory limit reached for the worker. terminating the worker. (used: {})", bytes_to_display(val));
Expand All @@ -287,7 +288,7 @@ impl EdgeRuntime {
};
rt.block_on(future);

if let Err(_) = halt_execution_tx.send(()) {
if let Err(_) = halt_isolate_tx.send(()) {
error!("failed to send the halt execution signal");
}
});
Expand Down
2 changes: 1 addition & 1 deletion crates/base/src/worker_ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl WorkerContext {
worker.run(recv_stream, shutdown_tx).await?;

// wait for shutdown signal
let _ = shutdown_rx.blocking_recv();
let _ = shutdown_rx.await;

Ok(())
});
Expand Down

0 comments on commit 7171ec7

Please sign in to comment.