ezieragabriel / arduino

Automatically exported from code.google.com/p/arduino
Other
0 stars 0 forks source link

TCP connections die after few seconds of inactivity #1024

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Hardware:
 - Arduino Leonardo
 - WiFi Shield

Software:
 - Arduino IDE 1.0.1
 - Mac OSX 10.7 / Ubuntu 12.04

Libraries:
 - WiFi Libraries (downloaded from arduino.cc)

What steps will reproduce the problem?
1. Code a sketch to open a TCP connection with a simple TCP server (I tried 
with a Node.js HelloWorld as server)
2. Sending and receiving messages works fine, so wait few seconds and the 
connection will be closed by the Arduino with a "reset" packet as the last 
packet sent from the board.
3. Now you can't send/receive anything more and the server is not correctly 
notified about the connection status until it tries to read/write.

What is the expected output? What do you see instead?
I expected the connection to be kept open until it was closed properly by the 
server/client. No other client (except for Arduino) seems to drop the 
connection in this way.

I'm gonna attach a wireshark log about the traffic produced by my TCP server 
and the board.

Kind Regards.
Marco Lipparini

Original issue reported on code.google.com by marco.li...@liarco.net on 31 Aug 2012 at 10:45

Attachments:

GoogleCodeExporter commented 9 years ago
The wireshark trace shows the disconnect happens 18 seconds after the last 
activity. 

Original comment by the.baum...@gmail.com on 5 Sep 2012 at 2:43

GoogleCodeExporter commented 9 years ago
I see... do you mean that can this be considered a normal behavior?

Original comment by marco.li...@liarco.net on 5 Sep 2012 at 3:15

GoogleCodeExporter commented 9 years ago
No. I agree with you that this is a bug. I see the same exact behavior with the 
Arduino WiFi shield in my testing. My tests with other devices like the Arduino 
Ethernet shield and Sparkfun WiFly shield do not exhibit this behavior.  They 
will remain connected. I was basically doing a +1 (a me too) but with 
information that is present in your capture and my capture.  I figured it may 
be useful to point out in text of this issue that this timer (wherever it is) 
appears to be 18 seconds.

Original comment by the.baum...@gmail.com on 5 Sep 2012 at 3:30

GoogleCodeExporter commented 9 years ago
I'm sorry, I misunderstood your message!

Thanks for your reply, I hope this bug will be fixed soon because it's really 
annoying! :(

Suggestion: now I made my Arduino sending an "heartbeat" packet every 
"FIXED_TIME" in order to avoid the disconnection... I hope that this can help 
other beginners out there while we wait for a real fix!

Original comment by marco.li...@liarco.net on 5 Sep 2012 at 4:07

GoogleCodeExporter commented 9 years ago
I also have the same problem and had to implement the same heart beat solution 
as a work around. The Arduino WiFi is an expensive shield and this kind of 
major bug is inacceptable in my opinion. Hopefully a fix is coming soon. 

Original comment by thebluel...@gmail.com on 6 Sep 2012 at 6:16

GoogleCodeExporter commented 9 years ago
Hello everyone, i want report that i have the same problem with WiFi Shield R3 
connected to the Arduino Uno R3 like Server using WiFi libraries (arduino.cc). 
Connection die after few seconds and it not occurs with Ethernet Shield 
(Arduino) and WiFly Shield (Sparkfun) i tested with library example code.
I hope that this bug will be soon fixed.
Thanks a lot.

Original comment by dariovit...@gmail.com on 3 Oct 2012 at 1:59

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Hi,
I am using WiFi Shield R3 connected to the Arduino Uno R3 like Server using 
WiFi libraries (arduino.cc). Connection dies after a few seconds. 

Original comment by marka65...@googlemail.com on 20 Oct 2012 at 8:50

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
I'm experiencing the same issue. This is most definitely a bug, otherwise it 
would be a *configurable* feature. I stumbled upon the same keepalive solution 
others did on my own, however, I'd like to get a proper fix.

Original comment by k...@vmfarms.com on 21 Oct 2012 at 1:45

GoogleCodeExporter commented 9 years ago
Furthermore, it seems like when the server initiates the disconnect due to 
timeout (without keepalive), I am no longer able to reconnect with the client. 
The port is open, but the client can never be served.

If the client initiates the disconnect (EOF), you can reconnect without issue.

Original comment by k...@vmfarms.com on 21 Oct 2012 at 4:21

GoogleCodeExporter commented 9 years ago
It seems as though if you call a server.status() after you've been 
disconnected, a 0 is returned, whereas 1 indicates it is healthy. There is no 
functionality to tear down a server and restart it from what I can tell from 
the firmware and libraries.

Original comment by k...@vmfarms.com on 21 Oct 2012 at 5:51

GoogleCodeExporter commented 9 years ago
The lwip (Light Weight IP)  tcp_poll function is being used by the firmware to 
define callback functions atcp_poll and atcp_poll_conn.

These are both checked roughly once every two seconds.

There is a value called tcp_poll_retries that is checked in these functions.  

The TCP connection is aborted when tcp_poll_retries is > 4 (so 5) in atcp_poll 
or when tcp_poll_retries is > 8 (so 9) in atcp_poll_conn.

The tcp_poll_retries value is incremented by 1 every two seconds no data is 
sent.

The tcp_poll_retries value only appears to get reset to 0 when data is 
successfully sent [tcp_data_sent].  

So, this appears to be an intentional mechanism used to kill the TCP connection 
when no data has been sent for 10 seconds or 18 seconds respectively.

The firmware and WiFi shield library should be modified to allow the user to 
configure or disable this timer.

I have tried to import the wifiHD project into Eclipse so I could look at 
making the change on the firmware side.

I have the AVR-Eclipse plugin installed.

However, like others have mentioned I am not able to successfully import this 
project into Eclipse.

Arduino Developers please update the github files (or provide additional 
instructions) so that the user base can start to make changes.

Original comment by the.baum...@gmail.com on 23 Oct 2012 at 8:16

GoogleCodeExporter commented 9 years ago
Yes please. You can refer to 
http://arduino.cc/forum/index.php/topic,128424.0.html for a discussion on this 
issue and others with the wifi shield. Your comments would be appreciated there.

Original comment by k...@vmfarms.com on 23 Oct 2012 at 8:24

GoogleCodeExporter commented 9 years ago
The developers released a patched firmware to github this morning. I've flashed 
my board and it has taken care of my issues. I've posted an update in the 
arduino.cc forum topic above. Give it a shot.

Original comment by k...@vmfarms.com on 25 Oct 2012 at 3:34

GoogleCodeExporter commented 9 years ago
This issue has only been fixed for TCP servers. The problem still occurs when 
you create a TCP client, connect to any server, and leave it idle for a few 
seconds. The TCP client will disconnect. 

You can (and as a stopgap I am ) send heartbeat packets to keep it alive, but 
I'd prefer not to because I'm concerned about squeezing every drop of battery 
life out of this thing!

Original comment by Clck...@gmail.com on 15 Dec 2012 at 8:50