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

ibis-server Connection Refused: Startup Sequence Dependency Issue Causing SQL Query Failures #1497

Open
i-am-alvin opened this issue Mar 30, 2025 · 1 comment
Labels
bug Something isn't working

Comments

@i-am-alvin
Copy link

ibis-server Connection Refused: Startup Sequence Dependency Issue Causing SQL Query Failures

Description

When attempting to execute SQL queries through wren-ui, a connect ECONNREFUSED 172.18.0.2:8000 error occurs, preventing connections to the ibis-server. After investigation, this appears to be an issue with the Docker container startup sequence, where service dependencies are not properly handled. Even though the ibis-server's HTTP service is running, its API endpoints remain unresponsive until all related services are restarted in a specific order.

Steps to Reproduce

  1. Start WrenAI Docker containers: docker compose up -d
  2. Try to execute an SQL query similar to:
SELECT COUNT("dud"."user_id") FROM "dim_user_data" AS "dud" 
WHERE CAST("dud"."joined_at_tw" AS TIMESTAMP WITH TIME ZONE) >= CAST('2025-03-30 00:00:00' AS TIMESTAMP WITH TIME ZONE) 
AND CAST("dud"."joined_at_tw" AS TIMESTAMP WITH TIME ZONE) < CAST('2025-03-31 00:00:00' AS TIMESTAMP WITH TIME ZONE)
  1. Observe the error: connect ECONNREFUSED 172.18.0.2:8000

Environment

  • Docker version: Docker version 24.0.6 (or higher)
  • WrenAI version: 0.18.0
  • wren-engine version: 0.14.8
  • wren-ai-service version: 0.18.2
  • wren-ui version: 0.23.4
  • OS: macOS 14.3.0

Expected Behavior

SQL queries should execute normally without connection errors.

Actual Behavior

Encountering Invalid SQL syntax connect ECONNREFUSED 172.18.0.2:8000 error, unable to connect to ibis-server.

Investigation

  1. Checked ibis-server container status and logs, confirmed the service is started and listening on port 8000
  2. Verified network configuration, confirming wrenai-ibis-server-1's IP address is 172.18.0.2
  3. Tested ibis-server's /health endpoint directly from the wren-ui container using curl, found it can connect normally
  4. Analyzed wren-ui logs, discovered that IbisAdaptor's connection attempts to ibis-server were being refused
  5. Examined ibis-server's JavaEngineConnector, found it depends on the wren-engine service

Solution

Restarting services in the following order resolved the issue:

  1. First restart wren-engine: docker restart wrenai-wren-engine-1
  2. Wait approximately 10 seconds, then restart ibis-server: docker restart wrenai-ibis-server-1
  3. Wait another 10 seconds, finally restart wren-ui: docker restart wrenai-wren-ui-1

Improvement Suggestions

  1. Add more explicit service dependencies and health checks in docker-compose.yaml
  2. Increase ibis-server startup delay to ensure wren-engine is fully initialized
  3. Improve error handling to provide more explicit error messages rather than just connection errors
  4. Consider implementing retry mechanisms to automatically retry when services are temporarily unavailable

Additional Notes

This issue may be more likely to reproduce in environments with limited system resources or slower networks, as service initialization times would be longer.

@i-am-alvin i-am-alvin added the bug Something isn't working label Mar 30, 2025
@wwwy3y3
Copy link
Member

wwwy3y3 commented Apr 2, 2025

@i-am-alvin

Wow. This issue is well written! Thanks a lot!

Add more explicit service dependencies and health checks in docker-compose.yaml

Yeah, I think adding healthcheck and condition: service_healthy to the depends_on configs we already have in docker-compose might be the easiest way to solve it.

Feel free to contribute if you'd like to, btw.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants