Skip to content

🐛 retry once on connection error#468

Open
ianardee wants to merge 1 commit into
mainfrom
fix-connreset
Open

🐛 retry once on connection error#468
ianardee wants to merge 1 commit into
mainfrom
fix-connreset

Conversation

@ianardee

Copy link
Copy Markdown
Collaborator

Description

Hi Mindee Team,

We are using the Mindee Node.js SDK (mindeeClient.enqueue()) in a Next.js / Vercel Serverless environment. We are consistently hitting an UND_ERR_SOCKET ("other side closed") error on our API routes. Because Vercel pauses serverless execution between invocations, Keep-Alive sockets in the connection pool go stale. When the function wakes up for the next request, undici grabs a pooled socket that the Mindee API (or its load balancer) has already closed, resulting in an immediate crash at bytesWritten: 0.

We have tried multiple aggressive workarounds to completely disable connection reuse and Keep-Alive, but the SDK seems to bypass or ignore them:

1. Using the SDK's dispatcher option

We passed a custom undici Agent to strictly disable pipelining and keep-alive pools:

import * as mindee from "mindee";
import { Agent } from "undici";

const mindeeClient = new mindee.Client({
  apiKey: process.env.MINDEE_API_KEY!,
  dispatcher: new Agent({
    pipelining: 0,
    keepAliveTimeout: 1,
    keepAliveMaxTimeout: 1
  }),
});

Result: Still throws "other side closed"

2. Monkey-patching https.request

We tried intercepting Node's underlying https module to force keepAlive: false:

const noKeepAliveAgent = new https.Agent({ keepAlive: false });
const originalHttpsRequest = https.request;
(https as any).request = function (url: any, options: any, cb: any) {
  if (typeof options === "object") options.agent = noKeepAliveAgent;
  return originalHttpsRequest(url, options, cb);
};

Result: Still throws "other side closed"

3. Setting Environment Variables

We also added MINDEE_REQUEST_TIMEOUT=60 and NODE_TLS_REJECT_UNAUTHORIZED=0 to our Vercel environment.

Despite all of this, the SDK continues to grab closed sockets from a pool somewhere and fails.

Types of changes

  • Docs change / refactoring / dependency upgrade
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Requires a change to the official Guide documentation.

@ianardee ianardee requested a review from sebastianMindee June 30, 2026 16:54
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