Skip to content

Commit

Permalink
feat: display memory leak warning for in-process handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
dnalborczyk committed Jun 6, 2022
1 parent da60c98 commit 2192a5f
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/lambda/handler-runner/in-process-runner/InProcessRunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export default class InProcessRunner {
#functionKey = null
#handlerName = null
#handlerPath = null
#memoryLeakWarning = true
#timeout = null

constructor(functionKey, handlerPath, handlerName, env, timeout, allowCache) {
Expand All @@ -29,6 +30,18 @@ export default class InProcessRunner {
// () => void
cleanup() {}

#showMemoryLeakWarning() {
// only display memory leak warning once
if (this.#memoryLeakWarning) {
log.warning()
log.warning(
`Running 'serverless-offline' and the handlers side-by-side in the same process with reloading enabled will cause memory leaks!`,
)
log.warning()
this.#memoryLeakWarning = false
}
}

async run(event, context) {
// check if the handler module path exists
if (!require.resolve(this.#handlerPath)) {
Expand All @@ -47,7 +60,11 @@ export default class InProcessRunner {

// lazy load handler with first usage
if (!this.#allowCache) {
await clearModule(this.#handlerPath, { cleanup: true })
this.#showMemoryLeakWarning()

await clearModule(this.#handlerPath, {
cleanup: true,
})
}

let handler
Expand Down

0 comments on commit 2192a5f

Please sign in to comment.