Tide: Error 'upstream prematurely closed connection while reading response header from upstream' while using nginx proxy

Created on 23 Apr 2020  路  5Comments  路  Source: http-rs/tide

I got a strange error while proxy from nginx to tide server.

steps:

  1. my app using tide as server and bound on 127.0.0.0:10086
  2. execute curl http://127.0.0.1:10086/test/code, everything is fine. and trace log of my app is:
{"level":10,"time":1587640196537,"msg":"registering with poller"}
{"level":30,"time":1587640196538,"msg":"spawn","task_id":"1","parent_task_id":"2"}
{"level":10,"time":1587640196539,"msg":"IN => GET /test/code"}
{"level":10,"time":1587640196539,"msg":"Server response encoding: start"}
{"level":10,"time":1587640196539,"msg":"Server response encoding: fixed length body"}
{"level":10,"time":1587640196541,"msg":"deregistering handle with poller"}
  1. config nginx proxy like below script:
server{
listen 443 ssl;
server_name my.host.com;
ssl_certificate /root/cert/spa.pem;
ssl_certificate_key /root/cert/spa.key;
ssl_session_timeout 5m;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://127.0.0.1:10086/;
proxy_redirect off;
}
}
  1. restart nginx.
  2. execute curl https://my.host.com/test/code ,502 Bad Gateway get returned. error log in /var/log/nginx/error.log is upstream prematurely closed connection while reading response header from upstream

and trace log of my app is:

{"level":30,"time":1587640196541,"msg":"completed","task_id":"1"}
{"level":10,"time":1587640212174,"msg":"registering with poller"}
{"level":30,"time":1587640212174,"msg":"spawn","parent_task_id":"2","task_id":"3"}
{"level":10,"time":1587640212175,"msg":"deregistering handle with poller"}

After change to using actix-web as server, both
curl http://127.0.0.1:10086/test/code and curl https://my.host.com/test/code works fine.

Is this an issue of tide or http-service-1?

Most helpful comment

@deities-online Here's what we believe is the fix:
Add proxy_http_version 1.1; to your nginx stanza. Please report back if that resolves the problem for you!

@jbr It works, Thanks!

It would be better to add some warning info in log.

All 5 comments

@deities-online it's hard to tell just from this log; could you perhaps share more details? In particular versions of tide, async-h1, async-std, and http-types would be relevant to know. You can find these in your Cargo.lock file. Thanks!

@deities-online it's hard to tell just from this log; could you perhaps share more details? In particular versions of tide, async-h1, async-std, and http-types would be relevant to know. You can find these in your Cargo.lock file. Thanks!

@yoshuawuyts Sorry, forgot provide version information.

I was using master brach of tide. compile env has been overwrite.

I reproduce this issue today:

execute commands:

Screen Shot 2020-04-24 at 10 40 57

output log of pm2:
Screen Shot 2020-04-24 at 10 39 46

os is Centos 7, nginx version refer to first image. and the Cargo.lock file is:
Cargo.lock.txt

If any information need, please let me know.

@deities-online Here's what we believe is the fix:
Add proxy_http_version 1.1; to your nginx stanza. Please report back if that resolves the problem for you!

@deities-online Here's what we believe is the fix:
Add proxy_http_version 1.1; to your nginx stanza. Please report back if that resolves the problem for you!

@jbr It works, Thanks!

It would be better to add some warning info in log.

@deities-online Good point about logging. Added #470 to reflect that need and closing this as resolved

Was this page helpful?
0 / 5 - 0 ratings