Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The proxy examples adds 5s to the PUT requests #327

Open
Keirua opened this issue May 28, 2020 · 0 comments
Open

The proxy examples adds 5s to the PUT requests #327

Keirua opened this issue May 28, 2020 · 0 comments
Labels
bug Something isn't working

Comments

@Keirua
Copy link

Keirua commented May 28, 2020

The http-proxy example seem to add 5s to every PUT requests. It seem to be due to some unexpected keep-alive timeout.
Below is a minimal (although not short) example in order to reproduce the issue.

Reproducing the issue

We'll send a PUT request using curl to the rust http-proxy server, and this server will proxy the request to a node backend.

node backend: a simple upload server

The upload server is a simple nodeJS server:

  • when you PUT /something.txt, it writes the body of the request in ./uploads/something.txt
  • when you GET /something.txt, it serves the file ./uploads/something.txt

package.json

{
  "dependencies": {
    "express": "^4.17.1",
    "http": "^0.0.0"
  }
}

server.js

var http = require('http');
var fs = require('fs');

var express = require('express');
var app = express();
const { Readable } = require('stream');

app.put('*', function(req, res) {
  req.pipe(fs.createWriteStream(__dirname + '/uploads/' +req.url));

  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('OK!');
});

app.use(express.static(__dirname + '/uploads'));
app.listen(3000);

Running the test

You'll need 3 terminals (or tmux, etc…).

First terminal: the upload server

mkdir uploads
npm install
# This server listens on port 3000
node server.js

Second terminal: the proxy server

# actix is listening on port 4444, and forwards things to
# our node server which listens on port 3000
cargo run 127.0.0.1 4444 127.0.0.1 3000

Third terminal: uploading/downloading files

Depending on if you perform a GET or PUT request, execution time is very different.

$ time curl -XPUT -H 'Content-Type: application/octet-stream' --data-binary @computer.svg 127.0.0.1:4444/computer.svg
real    0m5.008s
user    0m0.000s
sys 0m0.004s
$ time curl -XGET http://127.0.0.1:4444/computer.svg
…file content
# execution time for the GET request
real    0m0.011s
user    0m0.004s

The 5s is consistent, only on the PUT request. My sample file computer.svg weights 5882 bytes so size is out of the equation.
I did the same thing with a python flask server (whose code is here), it yields the same results.

On a more complex example with logging, it seems the extra 5s come from a Keep-alive timeut:

…
[2020-05-28T08:46:46Z TRACE actix_codec::framed] attempting to decode a frame
[2020-05-28T08:46:46Z TRACE actix_codec::framed] frame decoded from buffer
[2020-05-28T08:46:46Z INFO  actix_web::middleware::logger] 127.0.0.1:35050 "PUT /victory HTTP/1.1" 100 0 "-" "curl/7.52.1" 0.030986
[2020-05-28T08:46:51Z TRACE actix_http::h1::dispatcher] Keep-alive timeout, close connection
[2020-05-28T08:46:51Z TRACE mio::poll] deregistering handle with poller
[2020-05-28T08:46:51Z TRACE mio::poll] registering with poller
…

With some help to identify the root cause, I can totally make the fix, but I'm a bit lost in the codebase here.

@robjtede robjtede added the bug Something isn't working label Mar 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants