in src/eventHandlers/WorkerInitHandler.ts [63:85]
export function logColdStartWarning(delayInMs?: number): void {
// On reading a js file with function code('require') NodeJs tries to find 'package.json' all the way up to the file system root.
// In Azure files it causes a delay during cold start as connection to Azure Files is an expensive operation.
const scriptRoot = process.env.AzureWebJobsScriptRoot;
if (process.env.WEBSITE_CONTENTAZUREFILECONNECTIONSTRING && process.env.WEBSITE_CONTENTSHARE && scriptRoot) {
// Add delay to avoid affecting coldstart
if (!delayInMs) {
delayInMs = 5000;
}
setTimeout(() => {
access(path.join(scriptRoot, 'package.json'), constants.F_OK, (err) => {
if (isError(err)) {
worker.log({
message:
'package.json is not found at the root of the Function App in Azure Files - cold start for NodeJs can be affected.',
level: LogLevel.Debug,
logCategory: LogCategory.System,
});
}
});
}, delayInMs);
}
}