Skip to content

Invalid state: ReadableStream is locked #1332

@madanstc

Description

@madanstc

Hello, whenever we deploy to production, we are getting the following error:

Error [AI_APICallError]: Failed to process successful response
0|client | at processTicksAndRejections (null) {
0|client | url: 'https://api.openai.com/v1/responses',
0|client | requestBodyValues: [Object],
0|client | statusCode: 200,
0|client | responseHeaders: [Object],
0|client | responseBody: undefined,
0|client | isRetryable: false,
0|client | data: undefined,
0|client | [cause]: Error [TypeError]: Invalid state: ReadableStream is locked
0|client | at (null)
0|client | at processTicksAndRejections (null) {
0|client | code: 'ERR_INVALID_STATE',
0|client | toString: [Function: toString]
0|client | }
0|client | }
0|client | {"type":"stream_debug","stage":"ui_stream_on_error","chatId":"7ea858df-355e-4a13-9e62-c9fa01ae0c04","userId":"26dfc698-ae63-4270-a592-74fc7c61ab54","error":"Failed to process successful response","errorStack":"Error: Failed to process successful response\n at (/home/ubuntu/apps/ai-chatbot/apps/client/.next/dev/server/chunks/node_modules_ai_dist_index_mjs_b0116780..js:3709:68)\n at (/home/ubuntu/apps/ai-chatbot/apps/client/.next/dev/server/chunks/node_modules_ai_dist_index_mjs_b0116780..js:3319:55)\n at (/home/ubuntu/apps/ai-chatbot/apps/client/.next/dev/server/chunks/node_modules_ai_dist_index_mjs_b0116780..js:3773:15)\n at runUpdateMessageJob (/home/ubuntu/apps/ai-chatbot/apps/client/.next/dev/server/chunks/node_modules_ai_dist_index_mjs_b0116780..js:3772:46)\n at transform (/home/ubuntu/apps/ai-chatbot/apps/client/.next/dev/server/chunks/node_modules_ai_dist_index_mjs_b0116780..js:3319:19)\n at transform (/home/ubuntu/apps/ai-chatbot/apps/client/.next/dev/server/chunks/node_modules_ai_dist_index_mjs_b0116780..js:3318:33)\n at (native)\n at (native)\n at (native)\n at (native)\n at (native)\n at (native)\n at (native)\n at (native)\n at processTicksAndRejections (native)","timestamp":"2025-11-27T10:49:00.187Z"}

the setup is nginx as reverse proxy, and chatbot app running.

nginx config is

server {
listen 443 ssl;
server_name _;

ssl_certificate     /etc/nginx/ssl/ssl_certificate.crt;
ssl_certificate_key /etc/nginx/ssl/ssl_certificate_key.key;

# Proxy main app (Next.js)
location / {
    proxy_pass http://host.docker.internal:3000;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_set_header Host $host;

    # Important for streaming
    proxy_buffering off;
    proxy_cache_bypass $http_upgrade;
    chunked_transfer_encoding on;
}

# Route /mcp* to API with prefix stripping
location ~ ^/mcp/(.*)$ {
    proxy_pass http://host.docker.internal:3001/$1;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_buffering off;
    proxy_request_buffering off;
}

# Health endpoint
location = /health {
    return 200 "OK\n";
}

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions