Skip to content

Commit 29d2176

Browse files
authored
fix: simplify the shutdown reason due to the memory limit of the event record (#367)
* fix: simplify the shutdown reason due to the memory limit of the event record * chore: remove an unused dependency * chore: update `Cargo.lock`
1 parent ac6a0a4 commit 29d2176

File tree

8 files changed

+16
-35
lines changed

8 files changed

+16
-35
lines changed

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ glob = "0.3.1"
7979
httparse = "1.8"
8080
http = "0.2"
8181
faster-hex = "0.9.0"
82-
strum = "0.25"
8382

8483
# DEBUG
8584
# [patch.crates-io]

crates/base/src/rt_worker/supervisor/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use std::sync::Arc;
66
use cpu_timer::{CPUAlarmVal, CPUTimer};
77
use deno_core::v8::IsolateHandle;
88
use enum_as_inner::EnumAsInner;
9-
use event_worker::events::MemoryLimitDetail;
109
use futures_util::task::AtomicWaker;
1110
use log::error;
1211
use sb_workers::context::{Timing, UserWorkerMsgs, UserWorkerRuntimeOpts};
@@ -127,7 +126,7 @@ pub struct Arguments {
127126
pub cpu_timer_param: CPUTimerParam,
128127
pub supervisor_policy: SupervisorPolicy,
129128
pub timing: Option<Timing>,
130-
pub memory_limit_rx: mpsc::UnboundedReceiver<MemoryLimitDetail>,
129+
pub memory_limit_rx: mpsc::UnboundedReceiver<()>,
131130
pub pool_msg_tx: Option<mpsc::UnboundedSender<UserWorkerMsgs>>,
132131
pub isolate_memory_usage_tx: oneshot::Sender<IsolateMemoryStats>,
133132
pub thread_safe_handle: IsolateHandle,

crates/base/src/rt_worker/supervisor/strategy_per_request.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,9 @@ pub async fn supervise(args: Arguments, oneshot: bool) -> (ShutdownReason, i64)
176176
}
177177
}
178178

179-
Some(detail) = memory_limit_rx.recv() => {
179+
Some(_) = memory_limit_rx.recv() => {
180180
error!("memory limit reached for the worker: isolate: {:?}", key);
181-
complete_reason = Some(ShutdownReason::Memory(detail));
181+
complete_reason = Some(ShutdownReason::Memory);
182182
}
183183
}
184184

crates/base/src/rt_worker/supervisor/strategy_per_worker.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,11 +208,10 @@ pub async fn supervise(args: Arguments) -> (ShutdownReason, i64) {
208208
}
209209
}
210210

211-
// memory usage
212-
Some(detail) = memory_limit_rx.recv() => {
211+
Some(_) = memory_limit_rx.recv() => {
213212
terminate_fn();
214213
error!("memory limit reached for the worker: isolate: {:?}", key);
215-
return (ShutdownReason::Memory(detail), cpu_usage_ms);
214+
return (ShutdownReason::Memory, cpu_usage_ms);
216215
}
217216
}
218217
}

crates/base/src/rt_worker/worker_ctx.rs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ use cpu_timer::CPUTimer;
1111
use deno_config::JsxImportSourceConfig;
1212
use deno_core::{InspectorSessionProxy, LocalInspectorSession};
1313
use event_worker::events::{
14-
BootEvent, MemoryLimitDetail, ShutdownEvent, WorkerEventWithMetadata, WorkerEvents,
15-
WorkerMemoryUsed,
14+
BootEvent, ShutdownEvent, WorkerEventWithMetadata, WorkerEvents, WorkerMemoryUsed,
1615
};
1716
use futures_util::pin_mut;
1817
use http::StatusCode;
@@ -261,7 +260,7 @@ pub fn create_supervisor(
261260
timing: Option<Timing>,
262261
termination_token: Option<TerminationToken>,
263262
) -> Result<(Option<CPUTimer>, CancellationToken), Error> {
264-
let (memory_limit_tx, memory_limit_rx) = mpsc::unbounded_channel::<MemoryLimitDetail>();
263+
let (memory_limit_tx, memory_limit_rx) = mpsc::unbounded_channel();
265264
let (waker, thread_safe_handle) = {
266265
let js_runtime = &mut worker_runtime.js_runtime;
267266
(
@@ -294,32 +293,29 @@ pub fn create_supervisor(
294293
)
295294
});
296295

297-
let send_memory_limit_fn = move |detail: MemoryLimitDetail| {
298-
debug!(
299-
"memory limit triggered: isolate: {:?}, detail: {:?}",
300-
key, detail
301-
);
296+
let send_memory_limit_fn = move |kind: &'static str| {
297+
debug!("memory limit triggered: isolate: {:?}, kind: {}", key, kind);
302298

303-
if memory_limit_tx.send(detail).is_err() {
299+
if memory_limit_tx.send(()).is_err() {
304300
error!(
305-
"failed to send memory limit reached notification - isolate may already be terminating: kind: {}",
306-
<&'static str>::from(&detail)
301+
"failed to send memory limit reached notification(isolate may already be terminating): isolate: {:?}, kind: {}",
302+
key, kind
307303
);
308304
}
309305
};
310306

311307
worker_runtime.add_memory_limit_callback({
312308
let send_fn = send_memory_limit_fn.clone();
313309
move |_| {
314-
send_fn(MemoryLimitDetail::MemCheck);
310+
send_fn("mem_check");
315311
true
316312
}
317313
});
318314

319315
worker_runtime.js_runtime.add_near_heap_limit_callback({
320316
let send_fn = send_memory_limit_fn;
321317
move |current, _| {
322-
send_fn(MemoryLimitDetail::V8);
318+
send_fn("v8");
323319

324320
// give an allowance on current limit (until the isolate is
325321
// terminated) we do this so that oom won't end up killing the

crates/event_worker/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,4 @@ uuid.workspace = true
1717
serde.workspace = true
1818
anyhow.workspace = true
1919
tokio.workspace = true
20-
log.workspace = true
21-
strum = { workspace = true, features = ["derive"] }
20+
log.workspace = true

crates/event_worker/events.rs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use base_mem_check::MemCheckState;
22
use serde::{Deserialize, Serialize};
3-
use strum::IntoStaticStr;
43
use uuid::Uuid;
54

65
#[derive(Serialize, Deserialize, Debug)]
@@ -20,20 +19,11 @@ pub struct WorkerMemoryUsed {
2019
pub mem_check_captured: MemCheckState,
2120
}
2221

23-
#[derive(Serialize, Deserialize, IntoStaticStr, Debug, Clone, Copy)]
24-
#[serde(tag = "limited_by")]
25-
#[serde(rename_all = "snake_case")]
26-
#[strum(serialize_all = "snake_case")]
27-
pub enum MemoryLimitDetail {
28-
MemCheck,
29-
V8,
30-
}
31-
3222
#[derive(Serialize, Deserialize, Debug)]
3323
pub enum ShutdownReason {
3424
WallClockTime,
3525
CPUTime,
36-
Memory(MemoryLimitDetail),
26+
Memory,
3727
EarlyDrop,
3828
TerminationRequested,
3929
}

0 commit comments

Comments
 (0)