How to handle half-open TCP connection?

DrSegatron
Posts: 22
Joined: Tue Oct 10, 2017 2:46 pm

How to handle half-open TCP connection?

Postby DrSegatron » Fri Jun 08, 2018 12:40 pm

I have a TCP connection that works great as long as the other side works properly, but if the connection is cut for example because of a change of WiFi network on the other side the connection is stuck in half-open mode.

I regularly try to send data on this socket, so the connection loss should be detected immediately and give an exception in by select(), but when the connection is broken, lwIP is happy to keep send()ing data into the void until I get some random strange errors ( Connection already in progress (119) and No more processes (11)) instead of something like (Software caused connection abort (-1) or Connection reset by peer (104)).

I tried setsockopt()ing SO_SNDTIMEO, but I'm not sure this does anything. I saw there is some callback for timeouts, not sure if that's something to do with this, it seems to be part of the raw API.

Edit: On a related note, I have select() in one thread and send() in another thread. This has been working fine until I discovered the half-open problem, but now I read that lwIP send() and other functions are not thread safe? Do I need to handle my (asynchronous) send()s in my select() somwhow?

Anoz_1
Posts: 1
Joined: Fri Jun 08, 2018 5:24 pm

Re: How to handle half-open TCP connection?

Postby Anoz_1 » Fri Jun 08, 2018 5:30 pm

I am new to the Esp32, so confirm what I say.
I saw a comment in the documentation that wifi and ble can interfere with each other of both are using the same cpu. The example I saw showed directing wifi to cpu0 and bluetooth to cpu1, or something like that.
Please take that as a hint since I am so green.

DrSegatron
Posts: 22
Joined: Tue Oct 10, 2017 2:46 pm

Re: How to handle half-open TCP connection?

Postby DrSegatron » Sat Jun 09, 2018 8:50 pm

Not sure what you are trying to answer.

DrSegatron
Posts: 22
Joined: Tue Oct 10, 2017 2:46 pm

Re: How to handle half-open TCP connection?

Postby DrSegatron » Sun Jun 10, 2018 2:49 pm

After reducing this option to 3 from the default 12 it actually times out and excepts the socket as it should:

Code: Select all

Maximum number of retransmissions of data segments (TCP_MAXRTX)

Who is online

Users browsing this forum: abbas1375, Bing [Bot] and 102 guests