-
Notifications
You must be signed in to change notification settings - Fork 42
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
Add pooling and request limiting to prevent memory leaks #110
Changes from 47 commits
6c12e78
e968403
b515f13
5c7b52d
a33b0c5
f8326cd
cb383fe
ac4ea1b
0b9044f
fc0f995
e18b1fd
0ffaad7
3d26067
909d08a
1c91f34
a86c4c9
4b634bb
3f7b796
db3c5d6
68f6290
9167e77
70c3a22
aebc3d5
96a2e82
0cb98b7
a73874f
326b410
966a9df
488ad3c
a7708af
e01d6d4
eca5995
3d8a1c2
271c935
a7581dc
8d968d7
04a3e5e
65c28e2
a1b809e
102adbc
954d33f
6bc105d
b3c6a08
be0c0cb
fabcafa
56484b5
c59bea8
c133a1e
a657040
75bd3eb
c3b2269
1f9f696
f352bb8
0e6c8ba
0ad0b9d
5d18b81
b09b13b
0bd1222
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,9 @@ | ||
export interface BuiltScriptExecutorSchema { | ||
scriptPath: string; | ||
inspect: boolean; | ||
'inspect-brk': boolean; | ||
'trace-exit': boolean; | ||
'trace-uncaught': boolean; | ||
'trace-warnings': boolean; | ||
__unparsed__: string; | ||
} // eslint-disable-line |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,8 @@ export interface CliOptions { | |
port?: number; | ||
blueprint?: string; | ||
reset?: boolean; | ||
maxRequests?: number; | ||
maxJobs?: number; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know it's late in the process but now as this is basically ready I'm questioning how clear these names are. we're not limiting the total number of requests, and what is a job? what if we either renamed them or created them as sub-options like something like |
||
} | ||
|
||
export const enum WPNowMode { | ||
|
@@ -43,6 +45,8 @@ export interface WPNowOptions { | |
wpContentPath?: string; | ||
wordPressVersion?: string; | ||
numberOfPhpInstances?: number; | ||
maxRequests?: number; | ||
maxJobs?: number; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what's the interplay here between could we use |
||
blueprintObject?: Blueprint; | ||
reset?: boolean; | ||
} | ||
|
@@ -54,6 +58,8 @@ export const DEFAULT_OPTIONS: WPNowOptions = { | |
projectPath: process.cwd(), | ||
mode: WPNowMode.AUTO, | ||
numberOfPhpInstances: 1, | ||
maxRequests: 128, | ||
maxJobs: 1, | ||
reset: false, | ||
}; | ||
|
||
|
@@ -111,6 +117,8 @@ export default async function getWpNowConfig( | |
phpVersion: args.php as SupportedPHPVersion, | ||
projectPath: args.path as string, | ||
wordPressVersion: args.wp as string, | ||
maxRequests: args.maxRequests as number, | ||
adamziel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
maxJobs: args.maxJobs as number, | ||
port, | ||
reset: args.reset as boolean, | ||
}; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { PHPResponse } from '@php-wasm/universal'; | ||
import { NodePHP } from '@php-wasm/node'; | ||
import { Pool } from './pool'; | ||
|
||
export type nodePoolOptions = { | ||
spawn?: () => Promise<NodePHP>; | ||
reap?: (instance: NodePHP) => void; | ||
fatal?: (instance: NodePHP, error: any) => any; | ||
maxRequests?: number; | ||
maxJobs?: number; | ||
}; | ||
|
||
const defaultSpawn = async () => await NodePHP.load('8.2'); | ||
adamziel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
const defaultFatal = (instance: NodePHP, error: any) => | ||
new PHPResponse( | ||
500, | ||
{}, | ||
new TextEncoder().encode( | ||
`500 Internal Server Error:\n\n${String( | ||
error && error.stack ? error.stack : error | ||
)}` | ||
) | ||
); | ||
|
||
const defaultReap = (instance: NodePHP) => { | ||
try { | ||
instance.exit(); | ||
} catch { | ||
void 0; | ||
adamziel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
}; | ||
|
||
export class NodePool extends Pool { | ||
constructor({ | ||
maxRequests = 128, | ||
maxJobs = 1, | ||
spawn = defaultSpawn, | ||
fatal = defaultFatal, | ||
reap = defaultReap, | ||
} = {}) { | ||
super({ maxRequests, maxJobs, spawn, fatal, reap }); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why only add
-f
in this line of code but not the other ones? And why update theinteractive-code-block
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was getting an error during the build process due to the attempted removal of a non-existent file.
-f
preventsrm
from throwing errors when you try to remove a file that isn't there. I've reverted it locally and the issue doesn't seem to be happening anymore. I only applied this to php5 because I've seen that we're deprecating that.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aha! PHP is not in the Playground repo anymore so that entire
rm
line could be removed in a separate PR.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@adamziel See, that worries me. If someone still has that directory, and then moves to a version that doesn't have an
rm
call for it, then it won't be removed. I think we should definitely open the PR now, BUT I think we should hold off on actually merging it for a predetermined amount of time, so that this can run off. Let me know your thoughts.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#131
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How would someone still have that directory after
git pull
andnpm install
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@adamziel If someone pulled the package freshly then that directory wouldn't exist. But if someone were already working with it, and had it in a state where that directory exists, and then checked out a version where the
rm
call is gone, then the directory might persist unexpectedly.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The way I understand git is that checking out a newer revision where a file is removed does remove that file from the filesystem. Am I getting that wrong?