Fix large option payloads throwing E2BIG and ENAMETOOLONG (#37)
Follow-up to https://github.com/matrix-org/matrix-public-archive/pull/36
This commit is contained in:
parent
f738dbc1da
commit
7eaa103a28
|
@ -21,14 +21,15 @@ async function renderHydrogenToString(options) {
|
||||||
const { signal } = controller;
|
const { signal } = controller;
|
||||||
// We use a child_process because we want to be able to exit the process after
|
// We use a child_process because we want to be able to exit the process after
|
||||||
// we receive the SSR results.
|
// we receive the SSR results.
|
||||||
const child = fork(
|
const child = fork(require.resolve('./2-render-hydrogen-to-string-fork-script'), [], {
|
||||||
require.resolve('./2-render-hydrogen-to-string-fork-script'),
|
signal,
|
||||||
[JSON.stringify(options)],
|
//cwd: process.cwd(),
|
||||||
{
|
});
|
||||||
signal,
|
|
||||||
//cwd: process.cwd(),
|
// Pass the options to the child by sending instead of via argv because we
|
||||||
}
|
// will run into `Error: spawn E2BIG` and `Error: spawn ENAMETOOLONG` with
|
||||||
);
|
// argv.
|
||||||
|
child.send(options);
|
||||||
|
|
||||||
// Stops the child process if it takes too long
|
// Stops the child process if it takes too long
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
|
|
|
@ -4,17 +4,13 @@
|
||||||
// get the data and exit the process cleanly. We don't want Hydrogen to keep
|
// get the data and exit the process cleanly. We don't want Hydrogen to keep
|
||||||
// running after we get our initial rendered HTML.
|
// running after we get our initial rendered HTML.
|
||||||
|
|
||||||
const assert = require('assert');
|
|
||||||
|
|
||||||
const _renderHydrogenToStringUnsafe = require('./3-render-hydrogen-to-string-unsafe');
|
const _renderHydrogenToStringUnsafe = require('./3-render-hydrogen-to-string-unsafe');
|
||||||
|
|
||||||
(async () => {
|
// Only kick everything off once we receive the options. We pass in the options
|
||||||
|
// this way instead of argv because we will run into `Error: spawn E2BIG` and
|
||||||
|
// `Error: spawn ENAMETOOLONG` with argv.
|
||||||
|
process.on('message', async (options) => {
|
||||||
try {
|
try {
|
||||||
assert(
|
|
||||||
process.argv[2],
|
|
||||||
'No command-line arguments passed to `render-hydrogen-to-string-fork-script.js`. Make sure these are being passed in when we spawn the new process.'
|
|
||||||
);
|
|
||||||
const options = JSON.parse(process.argv[2]);
|
|
||||||
const resultantHtml = await _renderHydrogenToStringUnsafe(options);
|
const resultantHtml = await _renderHydrogenToStringUnsafe(options);
|
||||||
|
|
||||||
// Send back the data we need
|
// Send back the data we need
|
||||||
|
@ -35,4 +31,4 @@ const _renderHydrogenToStringUnsafe = require('./3-render-hydrogen-to-string-uns
|
||||||
// Throw the error so the process fails and exits
|
// Throw the error so the process fails and exits
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
})();
|
});
|
||||||
|
|
Loading…
Reference in New Issue