upstream prematurely closed connection while reading response header from upstream while file upload

I’m facing an issue with file uploads on my Node.js application hosted behind a Nginx server. The setup involves using the Express-Formidable package as middleware for handling file uploads, which are then sent to an AWS S3 bucket.

The problem is that the file upload request never completes—my API request continues processing until it hits the server timeout, and the file never reaches the S3 bucket. All other API calls work fine, but requests involving file uploads stall indefinitely. After I restart the PM2 process, everything works normally for a while before the issue reoccurs.

When I checked the Nginx error logs, I found the following entry:

Nginx Error Log:

2024/09/04 18:32:44 [error] 63421#63421: *9345 , client: <my_ip>, server: <backend_api>, request: "POST /api/v1/video-project HTTP/2.0", upstream: "http://127.0.0.1:4000/api/v1/video-project", host: "<backend_api>", referrer: "<backend_api>"

Here’s my Nginx config for the server (relevant parts included):

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>server {
listen 443 ssl http2;
client_max_body_size 600M;
# Proxy settings for the main API
location / {
proxy_pass http://localhost:4000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
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_send_timeout 7200s;
proxy_read_timeout 7200s;
proxy_buffer_size 64k;
proxy_buffers 16 32k;
proxy_busy_buffers_size 64k;
proxy_request_buffering off;
proxy_buffering off;
proxy_connect_timeout 300;
}
}
</code>
<code>server { listen 443 ssl http2; client_max_body_size 600M; # Proxy settings for the main API location / { proxy_pass http://localhost:4000; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; 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_send_timeout 7200s; proxy_read_timeout 7200s; proxy_buffer_size 64k; proxy_buffers 16 32k; proxy_busy_buffers_size 64k; proxy_request_buffering off; proxy_buffering off; proxy_connect_timeout 300; } } </code>
server {

listen 443 ssl http2;

client_max_body_size 600M;

# Proxy settings for the main API

location / {

proxy_pass http://localhost:4000;

proxy_http_version 1.1;

proxy_set_header Upgrade $http_upgrade;

proxy_set_header Connection 'upgrade';

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_send_timeout 7200s;

proxy_read_timeout 7200s;

proxy_buffer_size 64k;

proxy_buffers 16 32k;

proxy_busy_buffers_size 64k;

proxy_request_buffering off;

proxy_buffering off;

proxy_connect_timeout 300;

}

}

Questions:

  • Has anyone encountered similar issues with Nginx prematurely closing upstream connections during file uploads? What could be the root cause of this?

  • Could this be a configuration issue with Nginx or something related to the Node.js Express-Formidable package or AWS S3 SDK?

  • Any recommendations on how to debug or resolve this issue? Could this be related to buffer settings or timeout misconfigurations?

Any insights or suggestions would be highly appreciated!

What I’ve Tried:

  • Checked the Nginx error logs but couldn’t find anything beyond the log above.

  • Adjusted the client_max_body_size and proxy settings

1

Maybe you have a problem with ram memory on the server and your nodejsapplication takes all the RAM, try setting pm2 start app.js --max-memory-restart 500M
when starting the application .

Please run this command “free -m” on your Server’s Terminal as shown in the image below, It will give you the free space in MBs, and check if you have enough RAM storage on your server. May be your RAM storage is not enough to full fill your request.

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật