Skip to content

[BUG] "Port address already in use" did not report when using default addressΒ #430

@lemorage

Description

@lemorage

Describe the bug
I am using cocoindex server command, and it runs successfully. But on CocoIndexInsight, nothing shows up. It turns out port 8080 is already used by another service on my machine, but no error is reported.

(cocoindex) ☁  cocoindex [main] ⚑  uv run examples/text_embedding/main.py cocoindex server -c https://cocoindex.io
Server running at http://127.0.0.1:8080/
Open CocoInsight at: https://cocoindex.io/cocoinsight
Press Enter to stop...

(cocoindex) ☁  cocoindex [main] lsof -i :8080
COMMAND   PID    USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
java     1491 clannad   44u  IPv6 0x57823e562640f127      0t0  TCP *:http-alt (LISTEN)
Python  13094 clannad   25u  IPv4 0x831a37ea00fc1ce5      0t0  TCP localhost:http-alt (LISTEN)

But in normal case, when cocoindex tries to use a port address that is already in use, it will fail as follows:

(cocoindex) ☁  cocoindex [main] ⚑  uv run examples/text_embedding/main.py cocoindex server -c https://cocoindex.io -a 127.0.0.1:7890

thread '<unnamed>' panicked at src/server.rs:76:10:
called `Result::unwrap()` on an `Err` value: Os { code: 48, kind: AddrInUse, message: "Address already in use" }
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Traceback (most recent call last):
  File "/Users/clannad/Dev/GitHub/cocoindex/examples/text_embedding/main.py", line 70, in <module>
    _run()
  File "/Users/clannad/Dev/GitHub/cocoindex/python/cocoindex/lib.py", line 71, in _inner
    return _run_cli()
           ^^^^^^^^^^
  File "/Users/clannad/Dev/GitHub/cocoindex/python/cocoindex/lib.py", line 49, in _run_cli
    return cli.cli.main(sys.argv[2:], prog_name=f"{sys.argv[0]} {sys.argv[1]}")
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/clannad/Dev/GitHub/cocoindex/.venv/lib/python3.12/site-packages/click/core.py", line 1082, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/Users/clannad/Dev/GitHub/cocoindex/.venv/lib/python3.12/site-packages/click/core.py", line 1697, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/clannad/Dev/GitHub/cocoindex/.venv/lib/python3.12/site-packages/click/core.py", line 1443, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/clannad/Dev/GitHub/cocoindex/.venv/lib/python3.12/site-packages/click/core.py", line 788, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/clannad/Dev/GitHub/cocoindex/python/cocoindex/cli.py", line 215, in server
    lib.start_server(server_settings)
  File "/Users/clannad/Dev/GitHub/cocoindex/python/cocoindex/lib.py", line 24, in start_server
    _engine.start_server(settings.__dict__)
pyo3_runtime.PanicException: called `Result::unwrap()` on an `Err` value: Os { code: 48, kind: AddrInUse, message: "Address already in use" }

To Reproduce

  1. Let some services run on port 8080, and then try to use python main.py cocoindex server -c https://cocoindex.io. No error will be reported.
  2. Let some services run on another port other than the default port addr, let's say 7890, and then try to use python main.py cocoindex server -c https://cocoindex.io -a 127.0.0.1:7890. The error will be reported.

Expected behavior
When an address is in use, the error should always be reported to the user.

CocoIndex Version
latest

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions