Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle overflown shared queue #1992

Merged
merged 4 commits into from Mar 24, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 32 additions & 0 deletions core/isolate.rs
Expand Up @@ -430,6 +430,9 @@ impl<B: Behavior> Future for Isolate<B> {
// there wasn't enough size, we will return the buffer via the
// legacy route, using the argument of deno_respond.
overflow_response = Some(buf);
// reset `polled_recently` so pending ops can be
// done even if shared space overflows
self.polled_recently = false;
break;
}

Expand Down Expand Up @@ -895,6 +898,35 @@ mod tests {
js_check(isolate.execute("check.js", "assert(asyncRecv == 1);"));
}

#[test]
fn overflow_res_multiple_dispatch_async() {
// TODO(ry) This test is quite slow due to memcpy-ing 100MB into JS. We
// should optimize this.
let mut isolate = TestBehavior::setup(TestBehaviorMode::OverflowResAsync);
js_check(isolate.execute(
"overflow_res_multiple_dispatch_async.js",
r#"
let asyncRecv = 0;
DenoCore.setAsyncHandler((buf) => {
assert(buf.byteLength === 100 * 1024 * 1024);
assert(buf[0] === 4);
asyncRecv++;
});
// Large message that will overflow the shared space.
let control = new Uint8Array([42]);
let response = DenoCore.dispatch(control);
assert(response == null);
assert(asyncRecv == 0);
// Dispatch another message to verify that pending ops
// are done even if shared space overflows
DenoCore.dispatch(control);
"#,
));
assert_eq!(isolate.behavior.dispatch_count, 2);
assert_eq!(Ok(Async::Ready(())), isolate.poll());
js_check(isolate.execute("check.js", "assert(asyncRecv == 2);"));
}

#[test]
fn test_js() {
let mut isolate = TestBehavior::setup(TestBehaviorMode::AsyncImmediate);
Expand Down