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

Python Container exits without logs in certain cases #1831

Closed
ucheNkadiCode opened this issue Apr 8, 2020 · 5 comments · Fixed by #1993
Closed

Python Container exits without logs in certain cases #1831

ucheNkadiCode opened this issue Apr 8, 2020 · 5 comments · Fixed by #1993

Comments

@ucheNkadiCode
Copy link
Contributor

When a user does the repro steps below, by default, the container starts and exits immediately without writing any meaningful error logs in the Debug Console.

Repro Steps:

  • During Add Docker Files to Workspace command, choose Python: Django or Python: Flask and select Port 1000.
  • After the lines
WORKDIR /app
ADD . /app

Add in

RUN useradd appuser && chown -R appuser /app
USER appuser
  • Hit F5 to run the container
  • Container will start and stop

Current solution to diagnose this issue:
Although it's possible to find out what's really happening in the container, it is a pain and the user cannot be expected to know/do these steps mentioned below.

  • Open and modify your launch.json file
  • Add "removeContainerAfterDebug": false, above "python" line
  • Run your container again
  • After it fails, navigate to docker explorer and click view logs
    image

In a Django app, you will see the error:

Error: You don't have permission to access that port.

In a Flask app, you may see the error:

self.socket.bind(self.server_address)
PermissionError: [Errno 13] Permission denied

This likely means you are exposing a system-port (ports 0 - 1023) while attempting to run as a non-root user. This incompatible configuration is demonstrated in the image above, but there must be an easier way to find this issue.

@bwateratmsft
Copy link
Collaborator

bwateratmsft commented Apr 8, 2020

IMO this is kinda a self-inflicted issue. Our scaffolding will do non-root if all ports are >1023, and root otherwise, so what we scaffold works--of course, it's impossible to stop users from creating something that doesn't work.

In general, this falls into the class of "startup errors". Because Python (and Node) do attach instead of launch (like .NET does), this means startup errors may happen before we have a chance to attach...which means they are missed and the container stops.

We still need to clean up containers in general because we cannot run a new one until the old one is gone, but there may be ways to change the timing of that, or possibly detect containers that shut down immediately before attach.

@haniamr
Copy link
Contributor

haniamr commented Apr 8, 2020

I think the problem here is that when the exception is thrown (due to the permission issue), it doesn't get written in the debug console. You can still debug and set breakpoints fine, so I don't think it is a startup issue since ptvsd doesn't execute the app process until something attaches to it.

@bwateratmsft
Copy link
Collaborator

In that case would this be a ptvsd issue? If anything, exceptions outta make it to the debug console.

@haniamr
Copy link
Contributor

haniamr commented Apr 10, 2020

Might be, I opened an issue over there: microsoft/ptvsd#2117

@bwateratmsft bwateratmsft changed the title Python Container exits without logs due to non-root user Python Container exits without logs in certain cases Apr 10, 2020
@bwateratmsft
Copy link
Collaborator

From that issue, it sounds like data is being written to stderr but Django is terminating itself before stderr is flushed.

@bwateratmsft bwateratmsft added this to the 1.2.0 milestone Apr 10, 2020
@dbreshears dbreshears added the P2 label Apr 14, 2020
@haniamr haniamr modified the milestones: 1.2.0, 1.3.0 Apr 28, 2020
@haniamr haniamr linked a pull request May 18, 2020 that will close this issue
@vscodebot vscodebot bot locked and limited conversation to collaborators Jul 4, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants