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

[BUG] - conda-store-server silently exits when port is already in use #562

Closed
asmeurer opened this issue Sep 6, 2023 · 3 comments · Fixed by #708
Closed

[BUG] - conda-store-server silently exits when port is already in use #562

asmeurer opened this issue Sep 6, 2023 · 3 comments · Fixed by #708
Assignees
Labels

Comments

@asmeurer
Copy link
Contributor

asmeurer commented Sep 6, 2023

Describe the bug

If you start conda-store-server when the configured port is already in use (e.g., because conda-store-server is already running), the process just silently exits.

Expected behavior

It should at least give an error message.

Actually, it should probably do one of the following:

  • Automatically find a free port.
  • If it doesn't actually make sense for multiple conda-store servers to be running simultaneously, automatically check if an existing conda-store server is running somewhere and fail if it is.

Even if the latter is the case, finding a free port could be useful in case some other application is using port 5000.

How to Reproduce the problem?

Run conda-store-server then run conda-store-server again in a different terminal.

Output

This is the only output that appears

$ conda-store-server
INFO  [alembic.runtime.migration] Context impl SQLiteImpl.
INFO  [alembic.runtime.migration] Will assume non-transactional DDL.

However, you can tell what the real problem is if you make the following patch

diff --git a/conda-store-server/conda_store_server/server/app.py b/conda-store-server/conda_store_server/server/app.py
index 741a31d..8f2dde7 100644
--- a/conda-store-server/conda_store_server/server/app.py
+++ b/conda-store-server/conda_store_server/server/app.py
@@ -363,6 +363,10 @@ class CondaStoreServer(Application):
                     else []
                 ),
             )
+        except:
+            import traceback
+            traceback.print_exc()
+            raise
         finally:
             if self.standalone:
                 process.join()

Then you get the error in the additional printed traceback:

$ conda-store-server
INFO  [alembic.runtime.migration] Context impl SQLiteImpl.
INFO  [alembic.runtime.migration] Will assume non-transactional DDL.
Traceback (most recent call last):
  File "/Users/aaronmeurer/anaconda3/envs/conda-store-server-dev/lib/python3.10/site-packages/uvicorn/server.py", line 160, in startup
    server = await loop.create_server(
  File "/Users/aaronmeurer/anaconda3/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 48] error while attempting to bind on address ('0.0.0.0', 5000): address already in use

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/aaronmeurer/Documents/conda-store/conda-store-server/conda_store_server/server/app.py", line 352, in start
    uvicorn.run(
  File "/Users/aaronmeurer/anaconda3/envs/conda-store-server-dev/lib/python3.10/site-packages/uvicorn/main.py", line 587, in run
    server.run()
  File "/Users/aaronmeurer/anaconda3/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 "/Users/aaronmeurer/anaconda3/envs/conda-store-server-dev/lib/python3.10/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/Users/aaronmeurer/anaconda3/envs/conda-store-server-dev/lib/python3.10/asyncio/base_events.py", line 628, in run_until_complete
    self.run_forever()
  File "/Users/aaronmeurer/anaconda3/envs/conda-store-server-dev/lib/python3.10/asyncio/base_events.py", line 595, in run_forever
    self._run_once()
  File "/Users/aaronmeurer/anaconda3/envs/conda-store-server-dev/lib/python3.10/asyncio/base_events.py", line 1881, in _run_once
    handle._run()
  File "/Users/aaronmeurer/anaconda3/envs/conda-store-server-dev/lib/python3.10/asyncio/events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File "/Users/aaronmeurer/anaconda3/envs/conda-store-server-dev/lib/python3.10/site-packages/uvicorn/server.py", line 78, in serve
    await self.startup(sockets=sockets)
  File "/Users/aaronmeurer/anaconda3/envs/conda-store-server-dev/lib/python3.10/site-packages/uvicorn/server.py", line 170, in startup
    sys.exit(1)
SystemExit: 1

Versions and dependencies used.

No response

Anything else?

No response

@asmeurer asmeurer added the type: bug 🐛 Something isn't working label Sep 6, 2023
@trallard trallard added this to the 🚀 JATIC - Q1 milestone Sep 11, 2023
@pavithraes
Copy link
Member

From today's meeting, we should have a helpful error message here. Also, as a sidenote, we should change the default port to something other than 5000 (because 5000 doesn't work on Mac machines).

@pierrotsmnrd
Copy link
Contributor

For developers, it makes total sense to have two simultaneously running instances of conda-store, for instance to compare behaviors after a modification. Note that in this context, we're talking of two different versions running simultaneously, or twice the same version from two different directories.

For the users, I don't see any scenario requiring two instances running simultaneously but I'd rather not limit what users can do.

So I think multiple instances running should be supported.

Now, two cases :

  • Either the user asks explicitly for a given port, and if it is in use, it should fail and ask to use a different port
  • Or the user didn't ask for a specific port, and then we can just set port 0 as default - uvicorn will pick a random free port instead.

We'll discuss the prefered behavior during our meeting.

@nkaretnikov
Copy link
Contributor

Status as of 5e4e2e5:

  • we've already moved the default port to 8080 (from 5000), so it no longer clashes with AirPlay Receiver on macOS
  • address and port are user-configurable options, via traitlets
  • we need to print what address and port are used before the server is started
  • we need to warn users if address and port are already in use - the except block by Aaron will do that.

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

Successfully merging a pull request may close this issue.

5 participants