conda-incubator / conda-store

Data science environments, for collaboration. ✨
https://conda.store
BSD 3-Clause "New" or "Revised" License
145 stars 50 forks source link

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

Closed asmeurer closed 10 months ago

asmeurer commented 1 year ago

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:

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

pavithraes commented 1 year ago

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 commented 1 year ago

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 :

We'll discuss the prefered behavior during our meeting.

nkaretnikov commented 10 months ago

Status as of 5e4e2e5: