abhinavsingh / proxy.py

💫 Ngrok FRP Alternative • ⚡ Fast • 🪶 Lightweight • 0️⃣ Dependency • 🔌 Pluggable • 😈 TLS interception • 🔒 DNS-over-HTTPS • 🔥 Poor Man's VPN • ⏪ Reverse & ⏩ Forward • 👮🏿 "Proxy Server" framework • 🌐 "Web Server" framework • ➵ ➶ ➷ ➠ "PubSub" framework • 👷 "Work" acceptor & executor framework
https://abhinavsingh.com/proxy-py-a-lightweight-single-file-http-proxy-server-in-python/
BSD 3-Clause "New" or "Revised" License
2.91k stars 568 forks source link

Wait until all data in buffer is flushed to client #1362

Closed YK-Samgo closed 2 months ago

YK-Samgo commented 4 months ago

Wait until all data in buffer is flushed to client when upstream server finishes.

This bug is met after #1361

With high performance upstream and large memory, proxy will keep a lot of data in buffer, and the upstream link may be closed by upstream server. Then proxy will mistake this shutdown as server tear down and kill the whole work even though there is still data in buffer.

I think it's more graceful to wait until all data flushed to client in this case.

This is a performance-related and random issue. I think it's also the reason of #498

In my server:

          1000M              10000M+
client ==== proxy.py ==== upstream server

May be there is a similar issue when upload large file, but I didn't meet. Or it won't be a problem since client will wait until response.

The bug #1361 will slow down the upstream so it will never be faster than client, which avoid the issue.

abhinavsingh commented 2 months ago

@YK-Samgo Thank you for the PR, and apologies for delaying the merge, was away from OSS for long. I have restarted the workflows and shall merge once after they passed. Best

abhinavsingh commented 2 months ago

@YK-Samgo Thanks a ton for pointing out this issue. I have cherry-picked your commit into this PR and made further enhancements. Would appreciate if you can review https://github.com/abhinavsingh/proxy.py/pull/1385