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

Fix stack overflow in KernelHost.run() #779

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/jsii-runtime/lib/host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class KernelHost {
return; // done
}

this.processRequest(req, () => this.run());
this.processRequest(req, () => setImmediate(() => this.run()));
}

private callbackHandler(callback: api.Callback) {
Expand Down
2 changes: 1 addition & 1 deletion packages/jsii-runtime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"scripts": {
"build": "tsc --build && chmod +x bin/jsii-runtime && /bin/bash ./bundle.sh",
"watch": "tsc --build -w",
"test": "/bin/bash test/playback-test.sh",
"test": "/bin/bash test/playback-test.sh && node test/stress-test.js",
"package": "package-js"
},
"devDependencies": {
Expand Down
26 changes: 26 additions & 0 deletions packages/jsii-runtime/test/stress-test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { InputOutput, Input, Output } from "../lib/in-out";
import { KernelHost } from "../lib/host";

const requestCount = 250000;

class FakeInputOutput extends InputOutput {
debug = false;
private count: number = 0;

write(_: Output) { }

read(): Input | undefined {
if(this.count == requestCount) {
return undefined;
}

++this.count;
return { api: 'stats' };
}
}

const inout = new FakeInputOutput();
const host = new KernelHost(inout, { debug: false, noStack: false });
host.run();

console.info("jsii-runtime stress test succeeded");