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

Log address and port, show exception trace from uvicorn.run #708

Merged
merged 3 commits into from
Jan 5, 2024

Conversation

nkaretnikov
Copy link
Contributor

@nkaretnikov nkaretnikov commented Dec 16, 2023

Fixes #562.

Description

This pull request:

  • logs address and port on startup
  • shows exception trace from uvicorn.run.

Example output when the port is already in use:

INFO  [app] Starting server on 0.0.0.0:8080
Traceback (most recent call last):
  File "/home/test/miniconda3/envs/conda-store-server-dev/lib/python3.10/site-packages/uvicorn/server.py", line 160, in startup
    server = await loop.create_server(
  File "/home/test/miniconda3/envs/conda-store-server-dev/lib/python3.10/asyncio/base_events.py", line 1493, in create_server
    raise OSError(err.errno, 'error while attempting '
OSError: [Errno 98] error while attempting to bind on address ('0.0.0.0', 8080): address already in use

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/test/conda-store/conda-store-server/conda_store_server/server/app.py", line 371, in start
    uvicorn.run(
  File "/home/test/miniconda3/envs/conda-store-server-dev/lib/python3.10/site-packages/uvicorn/main.py", line 587, in run
    server.run()
  File "/home/test/miniconda3/envs/conda-store-server-dev/lib/python3.10/site-packages/uvicorn/server.py", line 61, in run
    return asyncio.run(self.serve(sockets=sockets))
  File "/home/test/miniconda3/envs/conda-store-server-dev/lib/python3.10/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/home/test/miniconda3/envs/conda-store-server-dev/lib/python3.10/asyncio/base_events.py", line 628, in run_until_complete
    self.run_forever()
  File "/home/test/miniconda3/envs/conda-store-server-dev/lib/python3.10/asyncio/base_events.py", line 595, in run_forever
    self._run_once()
  File "/home/test/miniconda3/envs/conda-store-server-dev/lib/python3.10/asyncio/base_events.py", line 1881, in _run_once
    handle._run()
  File "/home/test/miniconda3/envs/conda-store-server-dev/lib/python3.10/asyncio/events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File "/home/test/miniconda3/envs/conda-store-server-dev/lib/python3.10/site-packages/uvicorn/server.py", line 78, in serve
    await self.startup(sockets=sockets)
  File "/home/test/miniconda3/envs/conda-store-server-dev/lib/python3.10/site-packages/uvicorn/server.py", line 170, in startup
    sys.exit(1)
SystemExit: 1

Pull request checklist

  • Did you test this change locally?
  • Did you update the documentation (if required)?
  • Did you add/update relevant tests for this change (if required)?

Additional information

Copy link

netlify bot commented Dec 16, 2023

Deploy Preview for kaleidoscopic-dango-0cf31d canceled.

Name Link
🔨 Latest commit dd6142f
🔍 Latest deploy log https://app.netlify.com/sites/kaleidoscopic-dango-0cf31d/deploys/6596e34f8410750008d60b46

# up, self.log doesn't work here either
logger = logging.getLogger("app")
logger.setLevel(self.log_level)
logger.info(f"Starting server on {self.address}:{self.port}")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could move this to initialize, then we'll be able to use self.log. But it'll be far from where uvicorn is actually started.

The lastResort handler is used by default. This might lead to unexpected
results because the lastResort handler has the WARNING log-level.

https://docs.python.org/3/library/logging.html#logging.lastResort
@trallard
Copy link
Collaborator

trallard commented Jan 4, 2024

ping @dcmcand for a review

Copy link
Contributor

@dcmcand dcmcand left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am a bit confused why self.log doesn't work in the start method while it does in the initialize method, but this seems to work and adds valuable info for people. 🚀

@nkaretnikov nkaretnikov merged commit 57054ad into conda-incubator:main Jan 5, 2024
18 checks passed
@nkaretnikov nkaretnikov deleted the port-reuse-562 branch January 5, 2024 19:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done 💪🏾
Development

Successfully merging this pull request may close these issues.

[BUG] - conda-store-server silently exits when port is already in use
3 participants