Golang不识别Close-Notifier。

huangapple go评论76阅读模式
英文:

Golang doesn't recognize Close-Notifier

问题

当我使用Apache mod_proxy将我的go请求转发到我的golang-web服务器时,我的go服务器无法识别客户端断开连接的情况。我正在使用close notifier:

notify := rw.(http.CloseNotifier).CloseNotify()
go func() {
    <-notify
    brk.closingClients <- cl.session.Value
}

当我使用防火墙的站点路径路由时,也不起作用。但是当我使用自己的golang反向代理时,它可以很好地工作,没有任何问题。使用Apache mod_proxy时,客户端在发送更多真实数据到go web服务器后才收到通知。

也许有人有办法解决我的问题,即在没有接收到任何更多数据的情况下,直接识别客户端断开连接的情况。

这是我的mod_proxy配置:

SSLProxyEngine On
ProxyRequests On
SSLProxyVerify none
SSLProxyCheckPeerCN off
SSLProxyCheckPeerName off
ProxyPass /event https://xxx.xxx.xxx.xxx:8888/event flushpackets=on keepalive=on
英文:

when I use Apache mod_proxy to forward my go-requests to my golang-webserver, my go-server doesn't recognize when client disconnects. I am using the close notifier:

notify := rw.(http.CloseNotifier).CloseNotify()
go func() {
		&lt;-notify
		brk.closingClients &lt;- cl.session.Value
}

When I use firewall sitepath rooting it doesn't work either.
But when I use my own golang reverse proxy it works verry well without any problems.
With my apache mod_proxy the client receives the notify after some more real data sended to the go webserver.

Perhaps somebody have a idea how can i solve my problem, that i recognize when clients disconnect directly, so without receiving any more data.

Here my mod_proxy configs

     SSLProxyEngine On
    ProxyRequests On
    SSLProxyVerify none
    SSLProxyCheckPeerCN off
    SSLProxyCheckPeerName off
    ProxyPass /event https://xxx.xxx.xxx.xxx:8888/event flushpackets=on  keepalive=on

答案1

得分: 3

Apache服务器在客户端断开连接时不会关闭连接。尽可能地重用连接对于服务器来说更加高效。

如果你真的希望反向代理每次重新连接(请注意可能会遇到性能或端口分配问题),你可以通过以下方式强制mod_proxy使用HTTP/1.0或在每次连接时显式关闭连接:

SetEnv force-proxy-request-1.0 1
SetEnv proxy-nokeepalive 1

https://httpd.apache.org/docs/2.4/mod/mod_proxy.html#envsettings

英文:

The Apache server isn't going to close the connection when the client disconnects. It's much more efficient for it to reuse the connection for as long as possible.

If you really want the reverse proxy to reconnect every time (beware you may run into performance or port allocation issues), you can force mod_proxy to use HTTP/1.0 or explicitly close the connections every time with either of:

SetEnv force-proxy-request-1.0 1
SetEnv proxy-nokeepalive 1

https://httpd.apache.org/docs/2.4/mod/mod_proxy.html#envsettings

huangapple
  • 本文由 发表于 2016年1月12日 16:16:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/34738551.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定