大网数据广告活动
服务器运维问答

Why would a client send a RST packet as reply to a SYN,ACK?

· 52CE 我爱测

I have a HTTP webservice where sometimes the connection setup fails in a strange way: client sends a SYN packet server sends a SYN,ACK reply client responds with RST In which situations could a client system decide to reply with …

问题原文

原帖链接 · oliver · CC BY-SA 3.0

I have a HTTP webservice where sometimes the connection setup fails in a strange way:

  • client sends a SYN packet
  • server sends a SYN,ACK reply
  • client responds with RST

In which situations could a client system decide to reply with RST packet? I could imagine this happens when the SYN,ACK contains eg. incorrect sequence numbers (but this doesn't seem to apply in my case - the sequence numbers look fine). So I'm interested in an exhaustive :-) list of cases where a client would send a RST packet after receiving the SYN,ACK packet.

In particular, is it possible for the client application code (using normal BSD-style socket API under Linux) to cause this RST packet, eg. by calling close() while 3-way handshake is still in progress?

已采纳解答

原帖链接 · oliver · CC BY-SA 3.0

For closure: the problem was a stupid bug in my code (in the client).

The client in this case uses nonblocking sockets, so the connect() call will return immediately while the kernel keeps waiting for the SYN,ACK packet from server. Unfortunately the client code was very impatient: if the connection wasn't established after a few hundred milliseconds, the client would call close() on the socket.

In some rare cases the SYN,ACK packets from the server would be delayed by several hundred milliseconds on their way through the network. When the delayed reply finally arrived at the client host, the kernel would see the socket was already closed, and would treat the SYN,ACK reply as belonging to an invalid socket. That's why it would reply with a RST packet to the server.

So yes, it is possible for the application code (using normal BSD-style socket API under Linux) to cause this RST packet: by using a nonblocking socket and closing the connection while the three-way handshake is still in progress.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2014-02-14)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。