luxonis / depthai-viewer

Log images, point clouds, etc, and visualize them effortlessly. Built in Rust using egui
https://rerun.io
Apache License 2.0
27 stars 2 forks source link

Errno 48] error while attempting to bind on address ('::1', 9001, 0, 0): address already in use #34

Closed Erol444 closed 7 months ago

Erol444 commented 1 year ago

When I try to run 0.1.4 depthai-viewer, I get the error below. I don't believe 0.1.4.alpha had this issue (I was able to boot my device). Dependencies were installed successfully. If I restart the Mac, it works, which leads me to believe the old depthai_viewer's backend didn't shut down properly.

erik@eriks-MacBook-Pro ~ % python3 -m depthai_viewer
Backend started successfully.
Exception in thread Thread-1 (start_api):
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/threading.py", line 1038, in _bootstrap_inner
    self.run()
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/depthai_viewer/venv-0.1.4/lib/python3.11/site-packages/sentry_sdk/integrations/threading.py", line 69, in run
    reraise(*_capture_exception())
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/depthai_viewer/venv-0.1.4/lib/python3.11/site-packages/sentry_sdk/_compat.py", line 60, in reraise
    raise value
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/depthai_viewer/venv-0.1.4/lib/python3.11/site-packages/sentry_sdk/integrations/threading.py", line 67, in run
    return old_run_func(self, *a, **kw)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/threading.py", line 975, in run
    self._target(*self._args, **self._kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/depthai_viewer/_backend/config_api.py", line 163, in start_api
    asyncio.run(main())
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/runners.py", line 190, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/base_events.py", line 653, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/depthai_viewer/_backend/config_api.py", line 142, in main
    async with websockets.serve(ws_api, "localhost", 9001):  # type: ignore[attr-defined]
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/depthai_viewer/venv-0.1.4/lib/python3.11/site-packages/websockets/legacy/server.py", line 1109, in __aenter__
    return await self
           ^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/depthai_viewer/venv-0.1.4/lib/python3.11/site-packages/websockets/legacy/server.py", line 1127, in __await_impl__
    server = await self._create_server()
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/base_events.py", line 1525, in create_server
    raise OSError(err.errno, 'error while attempting '
OSError: [Errno 48] error while attempting to bind on address ('::1', 9001, 0, 0): address already in use

When I shut down the depthai_viewer, this shows up in terminal, perhaps relevant:

[2023-09-06T16:46:27Z WARN  re_sdk_comms::server] Closing connection to client: early eof
/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/multiprocessing/resource_tracker.py:224: UserWarning: resource_tracker: There appear to be 9 leaked semaphore objects to clean up at shutdown
  warnings.warn('resource_tracker: There appear to be %d 
Erol444 commented 7 months ago

@zrezke would this be easy to solve?

zrezke commented 7 months ago

@Erol444 Yea, these stray backends can be easily recognized and killed. I'll take a look. Some sort of auto port negotiation or at least being able to specify the port would also be a nice addition, to be able to open up multiple viewers as well...

zrezke commented 7 months ago

Addressed this here: https://github.com/luxonis/depthai-viewer/pull/40