Reputation: 18953
I'm trying to figure out why my app's TCP/IP connection keeps hiccuping every 10 minutes (exactly, within 1-2 seconds). I ran Wireshark and discovered that after 10 minutes of inactivity the other end is sending a packet with the reset (RST) flag set. A google search tells me "the RESET flag signifies that the receiver has become confused and so wants to abort the connection" but that is a little short of the detail I need. What could be causing this? And is it possible that some router along the way is responsible for it or would this always come from the other endpoint?
Edit: There is a router (specifically a Linksys WRT-54G) sitting between my computer and the other endpoint -- is there anything I should look for in the router settings?
Upvotes: 172
Views: 758010
Reputation: 48356
Here are some cases where a TCP reset could be sent.
tcp_abort_on_overflow
is set. The server will send a reset to the client.time-wait
state, receives a message from the server-side, the client will send a reset to the server.Upvotes: 24
Reputation: 1
In general devices (the other end) have a TCP Keep Alive time setting which I think is set to 10 minutes in your case. The application needs to poll the device before that time, if not the other end send a TCP RST flag to close the connection. You may have to extend that time or modify your application to send requests more frequently than 10 minutes.
Upvotes: -1
Reputation: 436
One thing to be aware of is that many Linux netfilter firewalls are misconfigured.
If you have something like:
-A FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT
-A FORWARD -p tcp -j REJECT --reject-with tcp-reset
then packet reordering can result in the firewall considering the packets invalid and thus generating resets which will then break otherwise healthy connections.
Reordering is particularly likely with a wireless network.
This should instead be:
-A FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT
-A FORWARD -m state --state INVALID -j DROP
-A FORWARD -p tcp -j REJECT --reject-with tcp-reset
Basically anytime you have:
... -m state --state RELATED,ESTABLISHED -j ACCEPT
it should immediately be followed by:
... -m state --state INVALID -j DROP
It's better to drop a packet then to generate a potentially protocol disrupting tcp reset. Resets are better when they're provably the correct thing to send... since this eliminates timeouts. But if there's any chance they're invalid then they can cause this sort of pain.
Upvotes: 25
Reputation: 1
Just had a case. Client1 connected to Server. They are sending data via websocket protocol and the TCP connection is kept alived. Server is python flask and listening on Port 5000. Then Client2(same IP address as Client1) send a HTTP request to Server. Now if you interrupt Client1 to make it quit. Then a "connection reset by peer 104" happens in Server side and Client2.
Simply put, the previous connection is not safely closed and a request is sent immediately for a 3 way handshake. The Server side got confused and sent a RST message.
Upvotes: -1
Reputation: 1290
In most applications, the socket connection has a timeout. If there is no communication between the client and the server within the timeout, the connection is reset as you observe. A great example is a FTP server, if you connect to the server and just leave the connection without browsing or downloading files, the server will kick you off the connection, usually to allow other to be able to connect. I guess this is what you are experiencing with your connection. So take a look in the server application, if that is where you get the reset from, and see if it indeed has a timeout set for the connection in the source code.
Upvotes: 1
Reputation: 187
This is because there is another process in the network sending RST to your TCP connection.
Normally RST would be sent in the following case
In your case, it sounds like a process is connecting your connection(IP + port) and keeps sending RST after establish the connection.
Upvotes: 1
Reputation:
If there is a router doing NAT, especially a low end router with few resources, it will age the oldest TCP sessions first. To do this it sets the RST
flag in the packet that effectively tells the receiving station to (very ungracefully) close the connection. this is done to save resources.
Upvotes: 8
Reputation: 409
I've just spent quite some time troubleshooting this very problem. None of the proposed solutions worked. Turned out that our sysadmin by mistake assigned the same static IP to two unrelated servers belonging to different groups, but sitting on the same network. The end results were intermittently dropped vnc connections, browser that had to be refreshed several times to fetch the web page, and other strange things.
Upvotes: 16
Reputation: 107
RST is sent by the side doing the active close because it is the side which sends the last ACK. So if it receives FIN from the side doing the passive close in a wrong state, it sends a RST packet which indicates other side that an error has occured.
Upvotes: 9
Reputation: 9370
Run a packet sniffer (e.g., Wireshark) also on the peer to see whether it's the peer who's sending the RST or someone in the middle.
Upvotes: 29
Reputation: 39500
A 'router' could be doing anything - particularly NAT, which might involve any amount of bug-ridden messing with traffic...
One reason a device will send a RST is in response to receiving a packet for a closed socket.
It's hard to give a firm but general answer, because every possible perversion has been visited on TCP since its inception, and all sorts of people might be inserting RSTs in an attempt to block traffic. (Some 'national firewalls' work like this, for example.)
Upvotes: 105
Reputation: 21349
Some firewalls do that if a connection is idle for x number of minutes. Some ISPs set their routers to do that for various reasons as well.
In this day and age, you'll need to gracefully handle (re-establish as needed) that condition.
Upvotes: 7