pino: RangeError: WebAssembly.instantiate(): Out of memory: wasm memory
Hi,
I have a NextJS application which runs on the lts version of node (v16.13.2) and on a linux docker container.
I seem to be getting an error after the app has been running for a while where webAssembly is erroring due to running out of memory.
The error I managed to pull out is pretty vague but it has pino below it perhaps it’s draining web assemblies memory?
I have one custom transport which I have written (see below the error) this could have a memory leak in it I would like to get your opinion on it.
The worker exiting might be a consequence of the webAssembly error but I am not sure.
RangeError: WebAssembly.instantiate(): Out of memory: wasm memory
at node:internal/deps/cjs-module-lexer/dist/lexer:1:33593
at async initCJSParse (node:internal/modules/esm/translators:69:5)
at async ESMLoader.commonjsStrategy (node:internal/modules/esm/translators:176:18)
at async link (node:internal/modules/esm/module_job:67:21)
Error: the worker has exited
at ThreadStream.flushSync (/opt/application/node_modules/.pnpm/thread-stream@0.13.1/node_modules/thread-stream/index.js:281:13)
at process.onExit (/opt/application/node_modules/.pnpm/pino@7.6.5/node_modules/pino/lib/transport.js:65:12)
at process.emit (node:events:402:35)
at process.emit (node:domain:475:12)
at process.exit (node:internal/process/per_thread:184:15)
at /opt/application/node_modules/.pnpm/@sentry+node@6.17.3/node_modules/@sentry/node/dist/integrations/utils/errorhandling.js:24:24
at Array.<anonymous> (/opt/application/node_modules/.pnpm/@sentry+utils@6.17.3/node_modules/@sentry/utils/dist/syncpromise.js:103:37)
at /opt/application/node_modules/.pnpm/@sentry+utils@6.17.3/node_modules/@sentry/utils/dist/syncpromise.js:74:31
at Array.forEach (<anonymous>)
at SyncPromise._executeHandlers
import pino from 'pino';
import build from 'pino-abstract-transport';
import { createCloggerApi, postLogs, ILog } from '@api-clogger';
const { levels, version } = pino();
interface SplunkTransportOptions {
applicationName: string;
applicationVersion: string;
url: string;
}
const splunkTransport = async (options: SplunkTransportOptions) => {
if (!options.url) {
throw new Error('[@PINO TRANSPORT] - Empty url provided to the pino splunk transport');
}
const instance = createCloggerApi({ baseURL: options.url });
return build(
async function(source) {
for await (let log of source) {
try {
const { time, pid, hostname, msg, level, err, logger, correlation_id, correlationId, ...metadata } = log;
await postLogs(instance)([
{
time: new Date(time).toISOString(),
level: levels.labels[level] as ILog['level'],
logger: logger || `pino - v${version}`,
applicationName: options.applicationName || 'undefined application name',
applicationVersion: options?.applicationVersion || 'undefined application version',
correlationId: correlationId || correlation_id || 'correlation id not provided',
message: msg ? msg : metadata?.message,
stack: err?.stack,
metadata,
},
]);
} catch (error) {
console.error(error);
}
}
},
{
async close(err) {
if (err) {
console.error('[@ PINO TRANSPORT]', err);
}
},
},
);
};
export default splunkTransport;
module.exports = splunkTransport;
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 18 (16 by maintainers)
You shouldn’t create a new pino instance for every request: https://github.com/moshie/memory-issue/commit/102946eb6129f9b846bf3ad353fa33e5fa264fb6#diff-c1b593e8452344f7bae31fbb28f6489d240c99280ec645332dc7ae5e5fc5a9f6R15
There’s no reason why that isn’t declared globally