Skip to content

Commit

Permalink
Fix stack overflow in KernelHost.run()
Browse files Browse the repository at this point in the history
This commit fixes issue aws#778.
  • Loading branch information
ddinu-amzn committed Sep 13, 2019
1 parent 7b3b059 commit b4fe423
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
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");

0 comments on commit b4fe423

Please sign in to comment.