Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ceefour opened this issue Apr 1, 2020 · 13 comments

Comments

@ceefour
Copy link

ceefour commented Apr 1, 2020

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.

@ceefour ceefour changed the title fn invoke myapp hello on Windows: Error invoking function. status: 502 message: Container failed to initialize [fnserver] fn invoke myapp hello on Windows: Error invoking function. status: 502 message: Container failed to initialize Apr 1, 2020
@geroe1
Copy link

geroe1 commented Jul 7, 2022

Hi, getting the same error, when doing the tutorial https://fnproject.io/tutorials/JavaFDKIntroduction/
Is there an easy explanation, fix or workaround?
Thanks alot,
Georg

@geroe1
Copy link

geroe1 commented Aug 12, 2022

I found this log output in the server:

time="2022-08-12T09:58:19Z" level=debug msg="Exception in thread "main" com.fnproject.fn.runtime.exception.FunctionInitializationException: Unable to bind to unix socket in /tmp/iofs/lsnr.sock\n" app_id=01G7C30SYVNG8G00GZJ0000001 container_id=01GA8QV18RNG8G00GZJ000000T fn_id=01G7C753WANG8G00GZJ0000002 image="fndemo/javafn:0.0.11" tag=stderr
time="2022-08-12T09:58:19Z" level=debug msg="\tat com.fnproject.fn.runtime.HTTPStreamCodec.(HTTPStreamCodec.java:174)\n" app_id=01G7C30SYVNG8G00GZJ0000001 container_id=01GA8QV18RNG8G00GZJ000000T fn_id=01G7C753WANG8G00GZJ0000002 image="fndemo/javafn:0.0.11" tag=stderr
time="2022-08-12T09:58:19Z" level=debug msg="\tat com.fnproject.fn.runtime.EntryPoint.main(EntryPoint.java:69)\n" app_id=01G7C30SYVNG8G00GZJ0000001 container_id=01GA8QV18RNG8G00GZJ000000T fn_id=01G7C753WANG8G00GZJ0000002 image="fndemo/javafn:0.0.11" tag=stderr
time="2022-08-12T09:58:19Z" level=debug msg="Caused by: com.fnproject.fn.runtime.ntv.UnixSocketException: Error in bind:Operation not permitted\n" app_id=01G7C30SYVNG8G00GZJ0000001 container_id=01GA8QV18RNG8G00GZJ000000T fn_id=01G7C753WANG8G00GZJ0000002 image="fndemo/javafn:0.0.11" tag=stderr

Obviously, docker (colima) was not started with root user.

So, the fdk version was not the problem...

@pcross616
Copy link

I am getting the same issue on MacOS when using colima or rancher desktop.

the invoked function that is deployed when the fn container spins up doesn't seem to have a valid iofs on the host machine.

I tested with Docker Desktop and this works as expected.

@yufeifly
Copy link

yufeifly commented Sep 21, 2022 via email

@suneelkandali
Copy link

I am also having same issue, any solution to it?

@subprotocol
Copy link

subprotocol commented Oct 31, 2022

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

@pcross616
Copy link

Yup, can confirm the issue is nodev on the container mount volume for iofs. I was able to change it to anything not in my home dir path. I feel like it's a security policy issue with rancher desktop when mounting in the user home. The above docker command works great.

@suneelkandali
Copy link

The issue was resolved for me after applying above Docker command, ty

@ongnxco
Copy link

ongnxco commented Jul 18, 2023

I have the same issue on my Mac M1 with Docker and a fresh installation of FN. I am following the Node.js tutorial, and when I reach the part "fn invoke nodeapp nodefn," I encounter the error mentioned above. Here is the command to start FN with debug log level:

fn start --log-level DEBUG

¡¡¡ 'fn start' should NOT be used for PRODUCTION !!! see https://github.com/fnproject/fn-helm/
docker: Error response from daemon: Conflict. The container name "/fnserver" is already in use by container "d7ac23b0f59ed43134dd4e09415bcb0ff261cb23127af791b068474d0b6dd965". You have to remove (or rename) that container to be able to reuse that name.
See 'docker run --help'.

@Verun
Copy link

Verun commented Sep 8, 2023

I'm seeing this exact issue now on my Mac M1 (Ventura 13.2.1).

Docker Desktop version: 4.22.1
FnProject version: 0.6.26

Any workarounds?

@mariobustosjmz
Copy link

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

@funtom-io
Copy link

funtom-io commented Jan 27, 2024

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

Thank you, @mariobustosjmz, for this workaround. It solved the issue for me.
I'd like to know whether there will be a fix for that issue soon since I did not find a way to change the sharing implementation only for a group of containers.

@yufeifly
Copy link

yufeifly commented Jan 27, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants