Skip to content

Conversation

@Tobbe
Copy link
Member

@Tobbe Tobbe commented Jan 16, 2026

No more ECONNREFUSED on startup!

@netlify
Copy link

netlify bot commented Jan 16, 2026

Deploy Preview for cedarjs canceled.

Name Link
🔨 Latest commit 1ab6325
🔍 Latest deploy log https://app.netlify.com/projects/cedarjs/deploys/696a8293a877990008fd461e

@github-actions github-actions bot added this to the next-release milestone Jan 16, 2026
@nx-cloud
Copy link

nx-cloud bot commented Jan 16, 2026

🤖 Nx Cloud AI Fix

Ensure the fix-ci command is configured to always run in your CI pipeline to get automatic fixes in future runs. For more information, please see https://nx.dev/ci/features/self-healing-ci


View your CI Pipeline Execution ↗ for commit 1ab6325

Command Status Duration Result
nx run-many -t build:pack --exclude create-ceda... ✅ Succeeded 2s View ↗
nx run-many -t build ✅ Succeeded 5s View ↗
nx run-many -t test --minWorkers=1 --maxWorkers=4 ✅ Succeeded 1m 45s View ↗
nx run-many -t test:types ✅ Succeeded 10s View ↗

☁️ Nx Cloud last updated this comment at 2026-01-16 18:47:04 UTC

@nx-cloud
Copy link

nx-cloud bot commented Jan 16, 2026

🤖 Nx Cloud AI Fix

Ensure the fix-ci command is configured to always run in your CI pipeline to get automatic fixes in future runs. For more information, please see https://nx.dev/ci/features/self-healing-ci


View your CI Pipeline Execution ↗ for commit 1ab6325

Command Status Duration Result
nx run-many -t build ✅ Succeeded 5s View ↗
nx run-many -t test:types ✅ Succeeded 10s View ↗
nx run-many -t build:pack --exclude create-ceda... ✅ Succeeded <1s View ↗
nx run-many -t test --minWorkers=1 --maxWorkers=4 ✅ Succeeded 1m 25s View ↗

☁️ Nx Cloud last updated this comment at 2026-01-16 18:34:15 UTC

@nx-cloud
Copy link

nx-cloud bot commented Jan 16, 2026

🤖 Nx Cloud AI Fix

Ensure the fix-ci command is configured to always run in your CI pipeline to get automatic fixes in future runs. For more information, please see https://nx.dev/ci/features/self-healing-ci


View your CI Pipeline Execution ↗ for commit 1ab6325

Command Status Duration Result
nx run-many -t build ✅ Succeeded 5s View ↗
nx run-many -t build:pack --exclude create-ceda... ✅ Succeeded 4s View ↗
nx run-many -t test --minWorkers=1 --maxWorkers=4 ✅ Succeeded 1m 45s View ↗
nx run-many -t test:types ✅ Succeeded 10s View ↗

☁️ Nx Cloud last updated this comment at 2026-01-16 18:35:09 UTC

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Jan 16, 2026

Greptile Summary

Added a Vite plugin middleware that waits for the API server to be available before proxying GraphQL and API requests, replacing the previous approach of simply suppressing ECONNREFUSED errors for 2.5 seconds with active port polling.

Key changes:

  • New cedarWaitForApiServer plugin intercepts API-bound requests during development
  • Polls API server port every 500ms with 60-second timeout using TCP socket connections
  • Integrated into the main Vite plugin array to run before other middleware

Issues found:

  • Critical: Timeout handling still calls next(), which forwards requests to unavailable API server, defeating the purpose of waiting
  • Minor: GraphQL URL matching uses .includes() which could match unintended paths

Confidence Score: 2/5

  • This PR has a critical logic bug that prevents it from achieving its goal
  • The implementation contains a critical flaw where timeout errors still forward requests to the unavailable API server. While the approach of actively waiting for the API server is sound and improves on the previous timeout-based suppression, the bug means ECONNREFUSED errors will still occur after the 60-second timeout, which contradicts the PR's stated goal of eliminating these errors on startup
  • Pay close attention to packages/vite/src/plugins/vite-plugin-cedar-wait-for-api-server.ts - the timeout error handling needs to return a 503 response instead of calling next()

Important Files Changed

Filename Overview
packages/vite/src/plugins/vite-plugin-cedar-wait-for-api-server.ts New plugin that waits for API server before proxying requests; has logic issue where timeout errors don't prevent request forwarding
packages/vite/src/index.ts Simple integration of new wait-for-API-server plugin into the plugin array

Sequence Diagram

sequenceDiagram
    participant Client as Browser
    participant Vite as Vite Dev Server
    participant Plugin as Wait-for-API Plugin
    participant API as API Server
    
    Client->>Vite: Request /graphql
    Vite->>Plugin: Middleware intercepts request
    
    alt API request detected
        Plugin->>Plugin: Check if URL matches API patterns
        loop Poll every 500ms (max 60s)
            Plugin->>API: Attempt TCP connection
            alt Connection successful
                API-->>Plugin: Port is open
                Plugin->>Vite: Call next()
                Vite->>API: Proxy request
                API-->>Vite: Response
                Vite-->>Client: Response
            else Connection failed
                API-->>Plugin: Port not ready
                Plugin->>Plugin: Wait 500ms and retry
            end
        end
        
        alt Timeout after 60s
            Plugin->>Plugin: Log error
            Plugin->>Vite: Call next() anyway
            Note over Plugin,Vite: BUG: Should return 503 instead
            Vite->>API: Proxy request (fails)
            API-->>Vite: ECONNREFUSED
            Vite-->>Client: Error
        end
    else Non-API request
        Plugin->>Vite: Call next() immediately
        Vite-->>Client: Handle normally
    end
Loading

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 files reviewed, 2 comments

Edit Code Review Agent Settings | Greptile


let shouldWait = false

if (url.includes('/graphql')) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: this check may match non-API URLs that happen to contain /graphql. consider using url === '/graphql' or url.startsWith('/graphql') for more precise matching

Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/vite/src/plugins/vite-plugin-cedar-wait-for-api-server.ts
Line: 27:27

Comment:
**style:** this check may match non-API URLs that happen to contain `/graphql`. consider using `url === '/graphql'` or `url.startsWith('/graphql')` for more precise matching

How can I resolve this? If you propose a fix, please make it concise.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I'm not entirely happy with the logic here. I'll do some more testing before merging this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants