Azure / Azure/azure-functions-host
Error when loading native node binary into job
- Dominant language
- C#
- Stars
- 2k
- Forks
- 482
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 38
Description
Hi, I'm trying to use a native Node library called Sharp (for image processing) in a webjob. The webjob is deployed as part of my Azure App Service instance and not as a Functions app.
When running the job, I get the following error:
```
Microsoft.Azure.WebJobs.Host.FunctionInvocationException: Microsoft.Azure.WebJobs.Host.FunctionInvocationException: Exception while executing function: Functions.ProcessImages ---> System.Exception: Error: A dynamic link library (DLL) initialization routine failed.
\\?\D:\local\Temp\jobs\continuous\scripthost\mvhbfltp.51e\ProcessImages\node_modules\sharp\build\Release\sharp.node at Error (native) at Object.Module._extensions..node (module.js:583:18) at Module.load (module.js:473:32) at tryModuleLoad (module.js:432:12) at Function.Module._load (module.js:424:3) at Module.require (module.js:483:17) at require (internal/module.js:20:19) at Object. (D:\local\Temp\jobs\continuous\scripthost\mvhbfltp.51e\ProcessImages\node_modules\sharp\index.js:12:13) at Module._compile (module.js:556:32) at Object.Module._extensions..js (module.js:565:10) at Module.load (module.js:473:32) at tryModuleLoad (module.js:432:12) at Function.Module._load (module.js:424:3) at Module.require (module.js:483:17) at require (internal/module.js:20:19) at Object. (D:\local\Temp\jobs\continuous\scripthost\mvhbfltp.51e\ProcessImages\index.js:11:15) at Module._compile (module.js:556:32) at Object.Module._extensions..js (module.js:565:10) at Module.load (module.js:473:32) at tryModuleLoad (module.js:432:12) at Function.Module._load (module.js:424:3) at Module.require (module.js:483:17)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Microsoft.Azure.WebJobs.Script.Description.FunctionInvokerBase.d__23.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Azure.WebJobs.Host.Executors.FunctionInvoker`1.d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.d__53.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.d__3b.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.d__36.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.d__1a.MoveNext()
--- End of inner exception stack trace ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.d__1a.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.d__2.MoveNext()
```
I'm running Node 6.9.1 x64 on Azure. When I compile the application on Appveyor, I'm also using Node 6.9.1 x64. Compilation works great, it's just the error above at runtime.
To be sure this wasn't an issue with the library itself, I created a test endpoint that utilizes the library in my main application and it works as expected.
#### Repro steps
Provide the steps required to reproduce the problem
1. Install 64-bit Node and setup app service to run it
2. Create a webjob that attempts to access the [Sharp](https://github.com/lovell/sharp) library.
3. Run the job
#### Expected behavior
The job runs without error.
#### Actual behavior
The job fails with the above error.
#### Related information
I'm running the `Functions 1.0.10635` runtime, but have also tried with the previous version.
Here's a link to the source for the job: https://gist.github.com/jamesdixon/ba35960d7a64890eda49cc78a68cf424
Thank you!
Contributor guide
Research direction
Start with the linked job source and the Sharp load at node_modules/sharp/index.js:11-12, then reproduce the webjob on Azure with Node 6.9.1 x64 and the Functions 1.0.10635 runtime. Done means the webjob loads Sharp and runs without the native DLL initialization error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- azure, node.js
- Domain
- backend, cloud
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100