-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Fix socket timeouts during local debugging #422
Conversation
This fixes socket.timeout errors about 60 seconds after attaching to a node.js remote debug session.
The patch was tested locally with |
Thanks for the change @felixbuenemann. The problem statement definitely makes sense but I don't know ignoring timeout will fix the problem. If the underlying socket timed out, wouldn't you need to re-connect somehow? |
Ideally, you would set the Timeout value when creating Docker client to be something large - ~10mins is sufficient? Turns out we create the Docker client three places (only one is actually necessary) - https://github.com/awslabs/aws-sam-cli/search?q=from_env&unscoped_q=from_env. We should refactor this to create the Docker client only in This sounds like a lot but it is actually pretty simple. Do you think you can make this change? I can guide you through the process. This will not only fix your problem but also remove the minor tech debt we incurred due to three places where we created docker client. |
The statement is inside a I'm not sure how a 10 minute timeout will help, because a debugging session could also take an hour, so any arbitrary value would likely be wrong. |
Btw. instead of recovering from socket timeouts (which are how long we wait on blocking operations, not network errors), we could also call |
I've been getting a time out error when running my Lambda, but it oddly goes away if I add something like a Manually added this patch on my machine, and it fixes the issue! Here is the error thrown when running....
|
I looked at the So while setting the timeout through @sanathkr Let me know what you think! |
@oniice Could you please reformat your backtrace to use triple-backticks (fenced code block) instead of single-backticks so it becomes more readable? |
I see the same issue for long-running lambdas that don't output any log messages, my backtrace is the same as @oniice and manually applying this patch fixes it. |
Sorry for the late reply. Thanks for clarifying. Timeout actually does not close the socket but simply reports that no new data is available. It makes sense to swallow the timeout then and keep polling. Also, from other reports, I understand that this can happen even in non-debugging case when your function runs for several minutes without printing anything to the console. Without this patch, such invocations will timeout & fail. As much as I don't like the unbounded infinite loop, there is value in doing it. This is especially okay for a CLI tool which isn't used in a production environment. Can we just add a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fantastic! Thanks for making this change and sticking through all the discussion 🎉 A one line solution is usually the hardest to reason about :)
Sheep it 🐑
@felixbuenemann Thanks for keeping with this! Congrats on the first PR :) |
I was running into a problem where
sam local invoke --debug-port 9222 myFunction
orsam local start-api --debug-port 9222
would crash with asocket.timeout
about 60 seconds after attaching to the debug session if there was no log output from the container.This PR works around the problem by ignoring
socket.timeout
in the docker attach code and is essential to make debugging via debug port usable – at least on macOS.Description of changes:
When attaching to a docker container
socket.timeout
is now ignored so that the attach loop keeps running during remote debug sessions.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.