fn: [fnserver] `fn invoke myapp hello` on Windows: Error invoking function. status: 502 message: Container failed to initialize

Description

fn invoke myapp hello failed with:

Error invoking function. status: 502 message: Container failed to initialize, please ensure you are using the latest fdk and check the logs

Steps to reproduce the issue:

D:\project_amanah\fn-tutorial>fn init --runtime node hello
Creating function at: ./hello
Function boilerplate generated.
func.yaml created.

D:\project_amanah\fn-tutorial>cd hello

D:\project_amanah\fn-tutorial\hello>fn create app myapp
Successfully created app:  myapp

D:\project_amanah\fn-tutorial\hello>fn deploy --app myapp --local
Deploying hello to app: myapp
Bumped to version 0.0.2
Building image hello:0.0.2 ......................................
Updating function hello using image hello:0.0.2...
Successfully created function: hello with hello:0.0.2

D:\project_amanah\fn-tutorial\hello>fn invoke myapp hello
Error invoking function. status: 502 message: Container failed to initialize, please ensure you are using the latest fdk and check the logs

Describe the results you received:

Error invoking function. status: 502 message: Container failed to initialize, please ensure you are using the latest fdk and check the logs

Logs:

INFO[2020-04-01T04:22:13Z] Fn serving on `:8080`                         type=full version=0.3.749INFO[2020-04-01T04:22:24Z] hot function terminated                       app_id=01E4SZ3B07NG8G00GZJ0000001 container_id=01E4SZKNSRNG8G00GZJ0000002 cpus= error="container exit code 3" fn_id=01E4SZ4R2VNG8G00GZJ0000002 idle_timeout=30 image="hello:0.0.2" memory=128
INFO[2020-04-01T04:22:24Z] hot function failure                          app_id=01E4SZ3B07NG8G00GZJ0000001 container_id=01E4SZKNSRNG8G00GZJ0000002 cpus= error="Container failed to initialize, please ensure you are using the latest fdk and check the logs" fn_id=01E4SZ4R2VNG8G00GZJ0000002 idle_timeout=30 image="hello:0.0.2" memory=128
INFO[2020-04-01T04:22:24Z] container wait error, sending error to client  action="server.handleFnInvokeCall)-fm" app_id=01E4SZ3B07NG8G00GZJ0000001 call_id=01E4SZKNSQNG8G00GZJ0000001 error="Container failed to initialize, please ensure you are using the latest fdk and check the logs" fn_id=01E4SZ4R2VNG8G00GZJ0000002
ERRO[2020-04-01T04:22:24Z] api error                                     action="server.handleFnInvokeCall)-fm" code=502 error="Container failed to initialize, please ensure you are using the latest fdk and check the logs" fn_id=01E4SZ4R2VNG8G00GZJ0000002

Describe the results you expected:

hello function executed.

Additional information you deem important (e.g. issue happens only occasionally):

Always reproducible. Also reproducible with go:

D:\project_amanah\fn-tutorial>fn init --runtime go hello-go
Creating function at: ./hello-go
Function boilerplate generated.
func.yaml created.

D:\project_amanah\fn-tutorial>cd hello-go

D:\project_amanah\fn-tutorial\hello-go>fn deploy --app myapp --local
Deploying hello-go to app: myapp
Bumped to version 0.0.2
Building image hello-go:0.0.2 .............................................................................................................................
Updating function hello-go using image hello-go:0.0.2...
Successfully created function: hello-go with hello-go:0.0.2

D:\project_amanah\fn-tutorial\hello-go>fn invoke myapp hello-go
Error invoking function. status: 502 message: Container failed to initialize, please ensure you are using the latest fdk and check the logs

Logs:

INFO[2020-04-01T04:29:44Z] hot function terminated                       app_id=01E4SZ3B07NG8G00GZJ0000001 container_id=01E4T013ESNG8G00GZJ0000005 cpus= error="container exit code 1" fn_id=01E4T00X9CNG8G00GZJ0000003 idle_timeout=30 image="hello-go:0.0.2" memory=128
INFO[2020-04-01T04:29:44Z] hot function failure                          app_id=01E4SZ3B07NG8G00GZJ0000001 container_id=01E4T013ESNG8G00GZJ0000005 cpus= error="Container failed to initialize, please ensure you are using the latest fdk and check the logs" fn_id=01E4T00X9CNG8G00GZJ0000003 idle_timeout=30 image="hello-go:0.0.2" memory=128
INFO[2020-04-01T04:29:44Z] container wait error, sending error to client  action="server.handleFnInvokeCall)-fm" app_id=01E4SZ3B07NG8G00GZJ0000001 call_id=01E4T013ESNG8G00GZJ0000004 error="Container failed to initialize, please ensure you are using the latest fdk and check the logs" fn_id=01E4T00X9CNG8G00GZJ0000003
ERRO[2020-04-01T04:29:44Z] api error                                     action="server.handleFnInvokeCall)-fm" code=502 error="Container failed to initialize, please ensure you are using the latest fdk and check the logs" fn_id=01E4T00X9CNG8G00GZJ0000003

Output of fn version (CLI command):

Client version is latest version: 0.5.96
Server version:  0.3.749

Additional environment details (OSX, Linux, flags, etc.):

Windows 10 Pro.

About this issue

Most upvoted comments

Our group recently started experiencing this issue when switching from Docker Desktop to Rancher Desktop. The issue we see applies to all FDK languages. We have included a workaround below.

Specifically we see in our logs:

Unable to connect to unix socket /tmp/iofs/lsnr.sock.tmp Error: listen EPERM: operation not permitted /tmp/iofs/lsnr.sock.tmp
Container failed to initialize, please ensure you are using the latest fdk and check the logs

Analysis if using Rancher Desktop

fn start will run a docker command that binds to volumes inside a users home directory. Binding volumes inside a users home directory works fine in Docker Desktop, but in Rancher Desktop volumes are mounted with the nodev option. This option prevents unix domain sockets from working—something all the FDKs require!

For example, if using the node-fdk with debug logging turned on—you’ll see this issue cause an EPERM error here: (https://github.com/fnproject/fdk-node/blob/master/fn-fdk.js#L336).

Workaround for Rancher Desktop:

Instead of using fn start, try the command below. It does the same thing but binds volumes under /tmp instead of your home directory. This got us unblocked.

docker run --rm -i --name fnserver \
-v /tmp/iofs:/iofs \
-e FN_IOFS_DOCKER_PATH=/tmp/iofs \
-e FN_IOFS_PATH=/iofs \
-v /tmp/data:/app/data \
-v /var/run/docker.sock:/var/run/docker.sock \
--privileged \
-p 8080:8080 \
--entrypoint ./fnserver \
-e FN_LOG_LEVEL=DEBUG fnproject/fnserver:latest

@ceefour @geroe1 @pcross616 @suneelkandali - Are any of you using Rancher Desktop by chance? If so, does this workaround resolve your issue?

Thanks

Hi All, About : Error invoking function. status: 502 message: Container failed to initialize, please ensure you are using the latest fdk and check the logs

I’ve faced this problem using my Mac, after 2 hours spend and trying to understand all error logs , I found a config in my docker settings… so , I’ve updated file sharing implementation of containers from VirtioFs (default) to osxfs legacy

after what then I’m able to invoke my function correctly.

Screenshot 2023-09-22 at 15 42 31