justmao945 / mallory

HTTP/HTTPS proxy over SSH
MIT License
319 stars 69 forks source link

[support] SSH caching? #18

Open mdavis-xyz opened 3 years ago

mdavis-xyz commented 3 years ago

My SSH server can sometimes take up to 30 seconds to accept an SSH connection. I don't have control over the server, so I can't fix this.

One of the main reasons I wanted to use mallory (instead of just an SSH tunnel done inside my python code that sends the HTTP requests) is that I wanted to spend 30 seconds connecting once, and then holding that connection open for minutes/hours/days, to make subsequent HTTP requests quick. i.e. sharing the SSH connection between multiple HTTP calls.

However I find that the round trip time through mallory is still approximately 30 seconds, which makes me suspect that a new SSH connection is being created for each HTTP request.

I tried to read the code to see how the caching of the SSH connection works, but I couldn't quite see what's happening. How is it supposed to work?

The mallory logs show a round trip time which is approximately 40 milliseconds, when my curl command takes about 30 seconds to return. So I think the time in the logs does not include the time required to set up the SSH tunnel. Perhaps it should?

Note that this command is slow:

curl -x localhost:1316 my.server.fqdn:80/path

But this one is fast:

curl -x localhost:1316 localhost:80/path