briefercloud / briefer

Dashboards and notebooks in a single place. Create powerful and flexible dashboards using code, or build beautiful Notion-like notebooks and share them with your team.
https://briefer.cloud
GNU Affero General Public License v3.0
3.53k stars 203 forks source link

API launches before Jupyter is up causing API to fail to connect to jupyter for some time. #56

Open an-2018 opened 1 month ago

an-2018 commented 1 month ago

Description: The system fails to check if Jupyter is running, resulting in repeated connection errors.

Steps to Reproduce:

  1. Start the application using the following command:
    docker run -d \
    -p 3000:3000 \
    -p 8080:8080 \
    -v briefer_psql_data:/var/lib/postgresql/data \
    -v briefer_jupyter_data:/home/jupyteruser \
    -v briefer_briefer_data:/home/briefer \
    briefercloud/briefer
  2. Wait for the server to initialize.
  3. Observe logs indicating failure to connect to Jupyter.

Note: have jupyter running on http://localhost:8888

Expected Behavior: The application should successfully verify if Jupyter is running without connection issues.

Actual Behavior: The following error message appears repeatedly in the logs:

Failed to check if Jupyter is running
err: {
  "type": "TypeError",
  "message": "fetch failed: connect ECONNREFUSED ::1:8888",
  "stack":
      TypeError: fetch failed
          at node:internal/deps/undici/undici:12618:11
          at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
      caused by: Error: connect ECONNREFUSED ::1:8888
          at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1555:16)
}
vieiralucas commented 1 month ago

Hi @an-2018 I think the problem is that we initialize both at the same time, so we get this error the first couple of times we try to connect to jupyter.

To fix that we can wait for jupyter to be reachable before launching the API.

This change should be made to docker/setup/api.py. Before spawning api by calling subprocess.run we can add a loop there that keeps trying to connect to jupyter before procedding. I also think we should use 127.0.0.1 here instead of localhost.