Skip to content

Commit 46aed51

Browse files
committed
tmp
1 parent d8cdb7e commit 46aed51

2 files changed

Lines changed: 16 additions & 11 deletions

File tree

packages/engine-multi/src/util/ensure-payload-size.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export const verify = async (
2626
if (algo === 'stream') {
2727
sizeBytes = await calculateSizeStream(value, limitBytes);
2828
} else {
29-
sizeBytes = calculateSizeStringify(value);
29+
sizeBytes = await calculateSizeStringify(value);
3030
}
3131

3232
if (sizeBytes > limitBytes) {
@@ -39,10 +39,13 @@ export const verify = async (
3939
}
4040
};
4141

42-
export const calculateSizeStringify = (value: any): number => {
43-
const str = typeof value === 'string' ? value : JSON.stringify(value);
44-
const size_bytes = Buffer.byteLength(str, 'utf8');
45-
return size_bytes;
42+
export const calculateSizeStringify = (value: any): Promise<number> => {
43+
return new Promise((resolve) => {
44+
const str = typeof value === 'string' ? value : JSON.stringify(value);
45+
const size_bytes = Buffer.byteLength(str, 'utf8');
46+
setTimeout(() => resolve(size_bytes), 10);
47+
return size_bytes;
48+
});
4649
};
4750

4851
export const calculateSizeStream = async (
@@ -87,7 +90,7 @@ export default async (payload: any, limit_mb: number = 10) => {
8790
for (const key of KEYS_TO_VERIFY) {
8891
if (key in payload) {
8992
try {
90-
await verify(payload[key], limit_mb, 'stream');
93+
await verify(payload[key], limit_mb, 'stringify');
9194
} catch (e: any) {
9295
if (e.name === 'PAYLOAD_TOO_LARGE') {
9396
Object.assign(
@@ -96,7 +99,7 @@ export default async (payload: any, limit_mb: number = 10) => {
9699
);
97100
newPayload.redacted = true;
98101
} else {
99-
console.log(e)
102+
console.log(e);
100103
}
101104
}
102105
}

packages/engine-multi/src/worker/pool.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,9 @@ function createPool(script: string, options: PoolOptions = {}, logger: Logger) {
100100

101101
// This will forward all internal console.debug() lines to the parent stdout
102102
// if (options.proxyStdout) {
103-
child.stdout!.on('data', (data) => {
104-
console.log(`${child.pid ?? ''} |> ${data.toString()}`);
105-
});
103+
child.stdout!.on('data', (data) => {
104+
console.log(`${child.pid ?? ''} |> ${data.toString()}`);
105+
});
106106
// }
107107

108108
logger.debug('pool: Created new child process', child.pid);
@@ -239,7 +239,9 @@ function createPool(script: string, options: PoolOptions = {}, logger: Logger) {
239239
if (!didTimeout) {
240240
resolve(evt.result);
241241

242-
finish(worker);
242+
setTimeout(() => {
243+
finish(worker);
244+
}, 10000);
243245
}
244246
} else if (evt.type === ENGINE_REJECT_TASK) {
245247
// Note that this is an unexpected error

0 commit comments

Comments
 (0)