Non keep-alive HTTP/1.x requests close the connection immediately with compressed responses
Hi all,
First of all, Thank you for the amazing work with vertx.
I am testing the Version 3.5.0 with an nginx reverse proxy.
If I turn off the keep-alive functionality, the HttpServerResponseImpl is not answering anything.
You can test using the following HTTP requests:
Not working
GET / HTTP/1.0.
Host: my-server.com
X-Real-IP: 127.0.0.1.
X-Forwarded-For: 127.0.0.1.
Connection: close.
Cache-Control: max-age=0.
Upgrade-Insecure-Requests: 1.
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.79 Safari/537.36.
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8.
Accept-Encoding: gzip, deflate.
Accept-Language: pt-BR,pt;q=0.8,en-US;q=0.6,en;q=0.4.
.
Working
GET / HTTP/1.1.
Host: my-server.com
X-Real-IP: 127.0.0.1.
X-Forwarded-For: 127.0.0.1.
Cache-Control: max-age=0.
Upgrade-Insecure-Requests: 1.
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.79 Safari/537.36.
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8.
Accept-Encoding: gzip, deflate.
Accept-Language: pt-BR,pt;q=0.8,en-US;q=0.6,en;q=0.4.
.
This is because of the Connection: close
After a debug, I found that if HttpServerResponseImpl line 442 keepAlive is false, it is working as expected
if (!keepAlive) {
closeConnAfterWrite();
closed = true;
}
So I suspect that the closeConnAfterWrite is not working as expected.
I would appreciate if you can take a look on it.
thanks we will investigate soon
can you provide a reproducer ? I've got a case that works here.
with HTTP/1.0 the Connection: close header has no meaning, what matters is the Connection: keep-alive header.
The easiest way to reproduce is to create a nginx reverse proxy to a vertx http app and then try to access it via the proxy
can you provide a small nginx configuration so we can try it ?
The following configuration should do the trick.
server {
listen *:80;
server_name my-server.com;
access_log /var/log/nginx/my-server-access.log combined;
error_log /var/log/nginx/my-server-error.log;
location / {
proxy_pass http://localhost:8080;
proxy_read_timeout 90;
proxy_connect_timeout 90;
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 Proxy "";
}
}
can you give a CURL command line to send to the proxy to do the check ?
This will call the proxy. Nginx will redirect to you app on port 8080
curl -XGET http://my-server.com
Don't forget to add the my-server to your host pointing to 127.0.0.1
I can't see where HTTP/1.0 is configured
it is default... if you don't pass in the configuration
proxy_http_version 1.1; proxy_set_header Connection "";
nginx will assume 1.0
ok, thanks will investigate
I've just tried and the server disconnects after the response is sent, here is my server app test:
Vertx vertx = Vertx.vertx();
HttpServer server = vertx.createHttpServer();
server.requestHandler(req -> {
System.out.println(req.version());
req.response().end("Hello World");
}).listen(8081);
full nginx config:
events {
}
http {
server {
listen *:8080;
server_name my-server.com;
location / {
proxy_pass http://localhost:8081;
proxy_read_timeout 90;
proxy_connect_timeout 90;
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 Proxy "";
}
}
}
This example worked for me as well...
maybe it comes from the application ?
I don't know. It looks like that the connection is closed before the event loop flushes the data. Maybe because your example is too simple, or there is nothing else in the event loop, things seems to work.
But this is just my guess, because when i turn on the keep-alive in the nginx, it is working flawless
Ok, just to give you one more feedback. Even with keep-alive, after sometime, the app started to not respond connections.
With 3.4.2 it is working perfectly
I will add a delay to see how it goes
it would be great if you can investigate and give more insight about what is causing the issue
I will.