HTTP KeepAlive连接由服务器关闭,但客户端同时发送了请求 [英] HTTP KeepAlive connection closed by server but client had sent a request in the mean time

查看:1006
本文介绍了HTTP KeepAlive连接由服务器关闭,但客户端同时发送了请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

方案如下:


  • 有一个http反向代理,它与应用服务器有一个持久连接池。它已收到客户端的请求,并在检查连接打开后向后端发出相同的请求

  • 同时,服务器在收到请求之前关闭连接,并且代理失败并出现错误从后端读取。

  • 向客户发送错误。

如何处理此竞争条件:
- 所有连接关闭应该由代理启动,而不是由后端服务器启动?
- 代理应该在因连接关闭而无法发送时重试请求?

How should this race condition be handled: - All connection close should be initiated by proxy and never by the backend server? - Proxy should retry request when it fails to send because of connection close?

推荐答案

代理只是通过流量。如果服务器已关闭连接,则即使有待处理的请求,代理也应立即关闭它。
但是,从客户端站点来看,描述的情况看起来像服务器没有返回请求的任何数据。这应该通过'keep-alive'握手来防止。

Proxy just passes through the traffic. If the server has closed the connection, proxy should also immediately close it, even if there is a request pending. However, from the client site the described situation looks like server hasn't returned any data for the request. This should be prevented by 'keep-alive' handshake.

在HTTP协议中,标题Connection:用于这种情况。客户端包括连接:保持活动,如果他想在处理请求后保持TCP会话打开(因此可以在同一TCP会话中发送下一个HTTP请求)。服务器仍然可以回复连接:关闭标题,这意味着TCP会话将被关闭。

In HTTP protocol the header "Connection:" is used for such case. Client includes "Connection: Keep-Alive" if he wants to keep the TCP session open after the request will be processed (so it will be possible to send the next HTTP request within the same TCP session). Server still may reply with "Connection: Close" header, which means TCP session will be closed anyways.

这篇关于HTTP KeepAlive连接由服务器关闭,但客户端同时发送了请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆