[GH-ISSUE #2469] HTTP 代理插件似乎不支持 TCP 连接重用(Connection: keep-alive) #1961

Closed
opened 2026-05-05 13:15:44 -06:00 by gitea-mirror · 1 comment
Owner

Originally created by @luangong on GitHub (Jul 5, 2021).
Original GitHub issue: https://github.com/fatedier/frp/issues/2469

使用的 frp 版本

0.37.0

操作系统版本与架构

服务端:Windows 10 (64-bit)
客户端:Windows 7 (32-bit)

问题描述

http_proxy 插件似乎不支持 HTTP/1.1 的 TCP 连接重用机制(Connection: keep-alive)。例如在中国大陆用浏览器访问 www.bing.com 会被 301 重定向到 cn.bing.com,如果通过 curl 命令向 www.bing.com 发送请求,frp 的 http_proxy 插件成功地返回了 301 Moved Permanently,但是当 curl 尝试重用与 frp 的 TCP 连接继续请求 cn.bing.com 时 frp 返回 500 Internal Server Error

虽然目前 Chrome 浏览器访问 www.bing.com 能正常重定向到 cn.bing.com,但是其他 HTTP 客户端可能会因为尝试重用与代理服务器的 TCP 连接而遭到拒绝,例如 Ubuntu 里 apt 更新软件包就会报 500 错误,其他客户端我没有试过,就不一一列举了。

具体错误信息如下:

HTTP/1.1
显示以上截图的文字内容(HTTP/1.1)
$ curl -vfsSL --proxy http://localhost:1080 http://www.bing.com > /dev/null
*   Trying ::1:1080...
* Connected to localhost (::1) port 1080 (#0)
> GET http://www.bing.com/ HTTP/1.1
> Host: www.bing.com
> User-Agent: curl/7.75.0
> Accept: */*
> Proxy-Connection: Keep-Alive
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 301 Moved Permanently
< Content-Length: 0
< Date: Sun, 04 Jul 2021 13:06:46 GMT
< Location: http://cn.bing.com/
<
* Connection #0 to host localhost left intact
* Issue another request to this URL: 'http://cn.bing.com/'
* Found bundle for host localhost: 0x18751f7a140 [serially]
* Can not multiplex, even if we wanted to!
* Re-using existing connection! (#0) with proxy localhost
* Connected to localhost (::1) port 1080 (#0)
> GET http://cn.bing.com/ HTTP/1.1
> Host: cn.bing.com
> User-Agent: curl/7.75.0
> Accept: */*
> Proxy-Connection: Keep-Alive
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 500 Internal Server Error
< Content-Type: text/plain; charset=utf-8
< X-Content-Type-Options: nosniff
< Date: Sun, 04 Jul 2021 13:05:27 GMT
< Content-Length: 17
<
* Connection #0 to host localhost left intact

注意上面加粗的部分。

如果在命令行参数中强制使用 HTTP/1.0 或指定 Connection: close 则一切正常:

HTTP/1.0
显示以上截图的文字内容(HTTP/1.0)
$ curl -vfsSL --http1.0 --proxy http://localhost:1080 http://www.bing.com > /dev/null
*   Trying ::1:1080...
* Connected to localhost (::1) port 1080 (#0)
> GET http://www.bing.com/ HTTP/1.0
> Host: www.bing.com
> User-Agent: curl/7.75.0
> Accept: */*
> Proxy-Connection: Keep-Alive
>
* Mark bundle as not supporting multiuse
* HTTP 1.0, assume close after body
< HTTP/1.0 301 Moved Permanently
< Content-Length: 0
< Date: Sun, 04 Jul 2021 13:15:05 GMT
< Location: http://cn.bing.com/
< Server: Microsoft-IIS/10.0
<
* Closing connection 0
* Issue another request to this URL: 'http://cn.bing.com/'
* Hostname localhost was found in DNS cache
*   Trying ::1:1080...
* Connected to localhost (::1) port 1080 (#1)
> GET http://cn.bing.com/ HTTP/1.0
> Host: cn.bing.com
> User-Agent: curl/7.75.0
> Accept: */*
> Proxy-Connection: Keep-Alive
>
* Mark bundle as not supporting multiuse
* HTTP 1.0, assume close after body
< HTTP/1.0 200 OK
< Cache-Control: private, max-age=0
< Content-Type: text/html; charset=utf-8
< Date: Sun, 04 Jul 2021 13:15:05 GMT
< P3p: CP="NON UNI COM NAV STA LOC CURa DEVa PSAa PSDa OUR IND"
< Vary: Accept-Encoding
< X-Cache: CONFIG_NOCACHE
< X-Snr-Routing: 1
<
* Closing connection 1
Connection: close
显示以上截图的文字内容(Connection: close
$ curl -vfsSL --header 'Connection: close' --proxy http://localhost:1080 http://www.bing.com > /dev/null
*   Trying ::1:1080...
* Connected to localhost (::1) port 1080 (#0)
> GET http://www.bing.com/ HTTP/1.1
> Host: www.bing.com
> User-Agent: curl/7.75.0
> Accept: */*
> Proxy-Connection: Keep-Alive
> Connection: close
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 301 Moved Permanently
< Content-Length: 0
< Date: Sun, 04 Jul 2021 13:21:22 GMT
< Location: http://cn.bing.com/
< Server: Microsoft-IIS/10.0
< Connection: close
<
* Closing connection 0
* Issue another request to this URL: 'http://cn.bing.com/'
* Hostname localhost was found in DNS cache
*   Trying ::1:1080...
* Connected to localhost (::1) port 1080 (#1)
> GET http://cn.bing.com/ HTTP/1.1
> Host: cn.bing.com
> User-Agent: curl/7.75.0
> Accept: */*
> Proxy-Connection: Keep-Alive
> Connection: close
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Cache-Control: private
< Content-Type: text/html; charset=utf-8
< Date: Sun, 04 Jul 2021 13:21:22 GMT
< P3p: CP="NON UNI COM NAV STA LOC CURa DEVa PSAa PSDa OUR IND"
< Vary: Accept-Encoding
< X-Cache: CONFIG_NOCACHE
< X-Snr-Routing: 1
< Connection: close
< Transfer-Encoding: chunked
<
* Closing connection 1

配置文件内容

服务器端配置文件 frps.ini

# frps.ini
[common]
bind_port = 7000

客户端配置文件 frpc.ini

# frpc.ini
[common]
server_addr = x.x.x.x
server_port = 7000

[plugin_http_proxy]
type = tcp
remote_port = 1080
plugin = http_proxy

日志文件内容

服务器端日志 frps.log

2021/07/05 12:19:39 [I] [root.go:200] frps uses config file: frps.ini
2021/07/05 12:19:39 [I] [service.go:192] frps tcp listen on 0.0.0.0:7000
2021/07/05 12:19:39 [I] [service.go:294] Dashboard listen on 0.0.0.0:7500
2021/07/05 12:19:39 [I] [root.go:209] frps started successfully
2021/07/05 12:19:44 [T] [service.go:396] start check TLS connection...
2021/07/05 12:19:44 [T] [service.go:404] success check TLS connection
2021/07/05 12:19:44 [I] [service.go:449] [cff8b28260f6eefa] client login info: ip [127.0.0.1:52971] version [0.37.0] hostname [] os [windows] arch [386]
2021/07/05 12:19:44 [I] [tcp.go:63] [cff8b28260f6eefa] [plugin_http_proxy] tcp proxy listen port [1080]
2021/07/05 12:19:44 [I] [control.go:444] [cff8b28260f6eefa] new proxy [plugin_http_proxy] success
2021/07/05 12:20:02 [I] [proxy.go:162] [cff8b28260f6eefa] [plugin_http_proxy] get a user connection [[::1]:53004]
2021/07/05 12:20:02 [D] [control.go:248] [cff8b28260f6eefa] get work connection from pool
2021/07/05 12:20:02 [D] [proxy.go:103] [cff8b28260f6eefa] [plugin_http_proxy] get a new work connection: [127.0.0.1:52971]
2021/07/05 12:20:02 [T] [proxy.go:262] [cff8b28260f6eefa] [plugin_http_proxy] handler user tcp connection, use_encryption: false, use_compression: false
2021/07/05 12:20:02 [D] [proxy.go:273] [cff8b28260f6eefa] [plugin_http_proxy] join connections, workConn(l[127.0.0.1:7000] r[127.0.0.1:52971]) userConn(l[[::1]:1080] r[[::1]:53004])
2021/07/05 12:20:02 [D] [control.go:219] [cff8b28260f6eefa] new work connection registered
2021/07/05 12:20:03 [D] [proxy.go:283] [cff8b28260f6eefa] [plugin_http_proxy] join connections closed

客户端日志 frpc.log

2021/07/05 12:19:44 [I] [service.go:304] [cff8b28260f6eefa] login to server success, get run id [cff8b28260f6eefa], server udp port [0]
2021/07/05 12:19:44 [I] [proxy_manager.go:144] [cff8b28260f6eefa] proxy added: [plugin_http_proxy]
2021/07/05 12:19:44 [T] [proxy_wrapper.go:171] [cff8b28260f6eefa] [plugin_http_proxy] change status from [new] to [wait start]
2021/07/05 12:19:44 [I] [control.go:180] [cff8b28260f6eefa] [plugin_http_proxy] start proxy success
2021/07/05 12:20:02 [D] [proxy_wrapper.go:231] [cff8b28260f6eefa] [plugin_http_proxy] start a new work connection, localAddr: 1.1.2.15:63118 remoteAddr: 1.1.2.2:7000
2021/07/05 12:20:02 [T] [proxy.go:739] [cff8b28260f6eefa] [plugin_http_proxy] handle tcp work connection, use_encryption: false, use_compression: false
2021/07/05 12:20:02 [D] [proxy.go:788] [cff8b28260f6eefa] [plugin_http_proxy] handle by plugin: http_proxy
2021/07/05 12:20:02 [D] [proxy.go:790] [cff8b28260f6eefa] [plugin_http_proxy] handle by plugin finished
2021/07/05 12:20:12 [E] [control.go:158] [cff8b28260f6eefa] work connection closed before response StartWorkConn message: EOF
2021/07/05 12:20:12 [D] [control.go:258] [cff8b28260f6eefa] read from control connection EOF
2021/07/05 12:20:12 [I] [control.go:282] [cff8b28260f6eefa] control writer is closing
2021/07/05 12:20:12 [I] [service.go:177] [cff8b28260f6eefa] try to reconnect to server...
2021/07/05 12:20:12 [I] [visitor_manager.go:60] [cff8b28260f6eefa] gracefully shutdown visitor manager

重现问题的步骤

  1. 准备两台机器,分别运行服务器端 frps 和客户端 frpc
  2. 在客户端配置文件中添加 plugin = http_proxy 并通知服务器端监听 1080 端口(remote_port = 1080)作为 HTTP 代理
  3. 在服务器端执行 curl -vfsSL --proxy http://localhost:1080 http://www.bing.com > /dev/null,控制台输出 500 Internal Server Error
Originally created by @luangong on GitHub (Jul 5, 2021). Original GitHub issue: https://github.com/fatedier/frp/issues/2469 <!-- From Chinese to English by machine translation, welcome to revise and polish. --> <!-- ⚠️⚠️ Incomplete reports will be marked as invalid, and closed, with few exceptions ⚠️⚠️ --> <!-- in addition, please use search well so that the same solution can be found in the feedback, we will close it directly --> <!-- for convenience of differentiation, use FRPS or FRPC to refer to the FRP server or client --> ## 使用的 frp 版本 0.37.0 ## 操作系统版本与架构 服务端:Windows 10 (64-bit) 客户端:Windows 7 (32-bit) ## 问题描述 `http_proxy` 插件似乎不支持 HTTP/1.1 的 TCP 连接重用机制(`Connection: keep-alive`)。例如在中国大陆用浏览器访问 [www.bing.com](http://www.bing.com) 会被 301 重定向到 [cn.bing.com](http://cn.bing.com),如果通过 `curl` 命令向 [www.bing.com](http://www.bing.com) 发送请求,frp 的 `http_proxy` 插件成功地返回了 `301 Moved Permanently`,但是当 `curl` 尝试重用与 frp 的 TCP 连接继续请求 [cn.bing.com](http://cn.bing.com) 时 frp 返回 `500 Internal Server Error`。 虽然目前 Chrome 浏览器访问 [www.bing.com](http://www.bing.com) 能正常重定向到 [cn.bing.com](http://cn.bing.com),但是其他 HTTP 客户端可能会因为尝试重用与代理服务器的 TCP 连接而遭到拒绝,例如 Ubuntu 里 apt 更新软件包就会报 500 错误,其他客户端我没有试过,就不一一列举了。 具体错误信息如下: <img width="640" alt="HTTP/1.1" src="https://user-images.githubusercontent.com/1857158/124416349-5f0ede00-dd89-11eb-8c5f-3a6351af8bf4.png"> <details> <summary>显示以上截图的文字内容(HTTP/1.1)</summary> <pre> <code>$ <strong>curl -vfsSL --proxy http://localhost:1080 http://www.bing.com > /dev/null</strong> * Trying ::1:1080... <strong>* Connected to localhost (::1) port 1080 (#0)</strong> > GET http://www.bing.com/ HTTP/1.1 > Host: www.bing.com > User-Agent: curl/7.75.0 > Accept: */* > Proxy-Connection: Keep-Alive > * Mark bundle as not supporting multiuse <strong>< HTTP/1.1 301 Moved Permanently</strong> < Content-Length: 0 < Date: Sun, 04 Jul 2021 13:06:46 GMT <strong>< Location: http://cn.bing.com/</strong> < * Connection #0 to host localhost left intact * Issue another request to this URL: 'http://cn.bing.com/' * Found bundle for host localhost: 0x18751f7a140 [serially] * Can not multiplex, even if we wanted to! <strong>* Re-using existing connection! (#0) with proxy localhost</strong> <strong>* Connected to localhost (::1) port 1080 (#0)</strong> > GET http://cn.bing.com/ HTTP/1.1 > Host: cn.bing.com > User-Agent: curl/7.75.0 > Accept: */* > Proxy-Connection: Keep-Alive > * Mark bundle as not supporting multiuse <strong>< HTTP/1.1 500 Internal Server Error</strong> < Content-Type: text/plain; charset=utf-8 < X-Content-Type-Options: nosniff < Date: Sun, 04 Jul 2021 13:05:27 GMT < Content-Length: 17 < * Connection #0 to host localhost left intact</code></pre> </details> 注意上面加粗的部分。 如果在命令行参数中强制使用 HTTP/1.0 或指定 `Connection: close` 则一切正常: <img width="720" alt="HTTP/1.0" src="https://user-images.githubusercontent.com/1857158/124416119-de4fe200-dd88-11eb-88d7-ecfb45414274.png"> <details> <summary>显示以上截图的文字内容(HTTP/1.0)</summary> <pre><code>$ curl -vfsSL <strong>--http1.0</strong> --proxy http://localhost:1080 http://www.bing.com > /dev/null * Trying ::1:1080... <strong>* Connected to localhost (::1) port 1080 (#0)</strong> > GET http://www.bing.com/ <strong>HTTP/1.0</strong> > Host: www.bing.com > User-Agent: curl/7.75.0 > Accept: */* > Proxy-Connection: Keep-Alive > * Mark bundle as not supporting multiuse * HTTP 1.0, assume close after body < HTTP/1.0 301 Moved Permanently < Content-Length: 0 < Date: Sun, 04 Jul 2021 13:15:05 GMT < Location: http://cn.bing.com/ < Server: Microsoft-IIS/10.0 < <strong>* Closing connection 0</strong> * Issue another request to this URL: 'http://cn.bing.com/' * Hostname localhost was found in DNS cache * Trying ::1:1080... <strong>* Connected to localhost (::1) port 1080 (#1)</strong> > GET http://cn.bing.com/ HTTP/1.0 > Host: cn.bing.com > User-Agent: curl/7.75.0 > Accept: */* > Proxy-Connection: Keep-Alive > * Mark bundle as not supporting multiuse * HTTP 1.0, assume close after body <strong>< HTTP/1.0 200 OK</strong> < Cache-Control: private, max-age=0 < Content-Type: text/html; charset=utf-8 < Date: Sun, 04 Jul 2021 13:15:05 GMT < P3p: CP="NON UNI COM NAV STA LOC CURa DEVa PSAa PSDa OUR IND" < Vary: Accept-Encoding < X-Cache: CONFIG_NOCACHE < X-Snr-Routing: 1 < <strong>* Closing connection 1</strong></code></pre> </details> <img width="727" alt="Connection: close" src="https://user-images.githubusercontent.com/1857158/124416283-3a1a6b00-dd89-11eb-80eb-5c7fa53a3bd7.png"> <details> <summary>显示以上截图的文字内容(<code>Connection: close</code>)</summary> <pre><code>$ curl -vfsSL <strong>--header 'Connection: close'</strong> --proxy http://localhost:1080 http://www.bing.com > /dev/null * Trying ::1:1080... <strong>* Connected to localhost (::1) port 1080 (#0)</strong> > GET http://www.bing.com/ HTTP/1.1 > Host: www.bing.com > User-Agent: curl/7.75.0 > Accept: */* > Proxy-Connection: Keep-Alive <strong>> Connection: close</strong> > * Mark bundle as not supporting multiuse < HTTP/1.1 301 Moved Permanently < Content-Length: 0 < Date: Sun, 04 Jul 2021 13:21:22 GMT < Location: http://cn.bing.com/ < Server: Microsoft-IIS/10.0 < Connection: close < <strong>* Closing connection 0</strong> * Issue another request to this URL: 'http://cn.bing.com/' * Hostname localhost was found in DNS cache * Trying ::1:1080... <strong>* Connected to localhost (::1) port 1080 (#1)</strong> > GET http://cn.bing.com/ HTTP/1.1 > Host: cn.bing.com > User-Agent: curl/7.75.0 > Accept: */* > Proxy-Connection: Keep-Alive <strong>> Connection: close</strong> > * Mark bundle as not supporting multiuse < HTTP/1.1 200 OK < Cache-Control: private < Content-Type: text/html; charset=utf-8 < Date: Sun, 04 Jul 2021 13:21:22 GMT < P3p: CP="NON UNI COM NAV STA LOC CURa DEVa PSAa PSDa OUR IND" < Vary: Accept-Encoding < X-Cache: CONFIG_NOCACHE < X-Snr-Routing: 1 < Connection: close < Transfer-Encoding: chunked < <strong>* Closing connection 1</strong></code></pre> </details> ## 配置文件内容 <!-- Please pay attention to hiding the token, server_addr and other privacy information --> 服务器端配置文件 `frps.ini`: ```ini # frps.ini [common] bind_port = 7000 ``` 客户端配置文件 `frpc.ini`: ```ini # frpc.ini [common] server_addr = x.x.x.x server_port = 7000 [plugin_http_proxy] type = tcp remote_port = 1080 plugin = http_proxy ``` ## 日志文件内容 ### 服务器端日志 `frps.log` ``` 2021/07/05 12:19:39 [I] [root.go:200] frps uses config file: frps.ini 2021/07/05 12:19:39 [I] [service.go:192] frps tcp listen on 0.0.0.0:7000 2021/07/05 12:19:39 [I] [service.go:294] Dashboard listen on 0.0.0.0:7500 2021/07/05 12:19:39 [I] [root.go:209] frps started successfully 2021/07/05 12:19:44 [T] [service.go:396] start check TLS connection... 2021/07/05 12:19:44 [T] [service.go:404] success check TLS connection 2021/07/05 12:19:44 [I] [service.go:449] [cff8b28260f6eefa] client login info: ip [127.0.0.1:52971] version [0.37.0] hostname [] os [windows] arch [386] 2021/07/05 12:19:44 [I] [tcp.go:63] [cff8b28260f6eefa] [plugin_http_proxy] tcp proxy listen port [1080] 2021/07/05 12:19:44 [I] [control.go:444] [cff8b28260f6eefa] new proxy [plugin_http_proxy] success 2021/07/05 12:20:02 [I] [proxy.go:162] [cff8b28260f6eefa] [plugin_http_proxy] get a user connection [[::1]:53004] 2021/07/05 12:20:02 [D] [control.go:248] [cff8b28260f6eefa] get work connection from pool 2021/07/05 12:20:02 [D] [proxy.go:103] [cff8b28260f6eefa] [plugin_http_proxy] get a new work connection: [127.0.0.1:52971] 2021/07/05 12:20:02 [T] [proxy.go:262] [cff8b28260f6eefa] [plugin_http_proxy] handler user tcp connection, use_encryption: false, use_compression: false 2021/07/05 12:20:02 [D] [proxy.go:273] [cff8b28260f6eefa] [plugin_http_proxy] join connections, workConn(l[127.0.0.1:7000] r[127.0.0.1:52971]) userConn(l[[::1]:1080] r[[::1]:53004]) 2021/07/05 12:20:02 [D] [control.go:219] [cff8b28260f6eefa] new work connection registered 2021/07/05 12:20:03 [D] [proxy.go:283] [cff8b28260f6eefa] [plugin_http_proxy] join connections closed ``` ### 客户端日志 `frpc.log` ``` 2021/07/05 12:19:44 [I] [service.go:304] [cff8b28260f6eefa] login to server success, get run id [cff8b28260f6eefa], server udp port [0] 2021/07/05 12:19:44 [I] [proxy_manager.go:144] [cff8b28260f6eefa] proxy added: [plugin_http_proxy] 2021/07/05 12:19:44 [T] [proxy_wrapper.go:171] [cff8b28260f6eefa] [plugin_http_proxy] change status from [new] to [wait start] 2021/07/05 12:19:44 [I] [control.go:180] [cff8b28260f6eefa] [plugin_http_proxy] start proxy success 2021/07/05 12:20:02 [D] [proxy_wrapper.go:231] [cff8b28260f6eefa] [plugin_http_proxy] start a new work connection, localAddr: 1.1.2.15:63118 remoteAddr: 1.1.2.2:7000 2021/07/05 12:20:02 [T] [proxy.go:739] [cff8b28260f6eefa] [plugin_http_proxy] handle tcp work connection, use_encryption: false, use_compression: false 2021/07/05 12:20:02 [D] [proxy.go:788] [cff8b28260f6eefa] [plugin_http_proxy] handle by plugin: http_proxy 2021/07/05 12:20:02 [D] [proxy.go:790] [cff8b28260f6eefa] [plugin_http_proxy] handle by plugin finished 2021/07/05 12:20:12 [E] [control.go:158] [cff8b28260f6eefa] work connection closed before response StartWorkConn message: EOF 2021/07/05 12:20:12 [D] [control.go:258] [cff8b28260f6eefa] read from control connection EOF 2021/07/05 12:20:12 [I] [control.go:282] [cff8b28260f6eefa] control writer is closing 2021/07/05 12:20:12 [I] [service.go:177] [cff8b28260f6eefa] try to reconnect to server... 2021/07/05 12:20:12 [I] [visitor_manager.go:60] [cff8b28260f6eefa] gracefully shutdown visitor manager ``` <!-- If the file is too large, use Pastebin, for example https://pastebin.ubuntu.com/ --> ## 重现问题的步骤 1. 准备两台机器,分别运行服务器端 frps 和客户端 frpc 2. 在客户端配置文件中添加 `plugin = http_proxy` 并通知服务器端监听 1080 端口(`remote_port = 1080`)作为 HTTP 代理 3. 在服务器端执行 `curl -vfsSL --proxy http://localhost:1080 http://www.bing.com > /dev/null`,控制台输出 `500 Internal Server Error`
gitea-mirror 2026-05-05 13:15:44 -06:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@fatedier commented on GitHub (Jul 5, 2021):

这个问题是由于使用了 yamux 库导致,给这个库提了一个 fix PR https://github.com/hashicorp/yamux/pull/91 ,合入后可以解决这个问题,如果不能被合入,会考虑在 frp 自身中做一层包装来解决。

<!-- gh-comment-id:873960728 --> @fatedier commented on GitHub (Jul 5, 2021): 这个问题是由于使用了 yamux 库导致,给这个库提了一个 fix PR https://github.com/hashicorp/yamux/pull/91 ,合入后可以解决这个问题,如果不能被合入,会考虑在 frp 自身中做一层包装来解决。
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: github-starred/frp#1961
No description provided.