Subject: Re: Megatools: Connection does not retry after dropping
From: Space
Date: Thu, 11 Mar 2021 19:32:38 +0000
That did indeed fix the problem of connection drops for me. I compiled megatools with the new option and disconnected my internet, once it was back megatools was able to continue downloading fairly quickly. In the case of an IP change (vpn disconnect/location change) it did not immediately recover but curl threw a "Failure when receiving data from the peer" error after a few (that I had not seen before) after the drop probably because curl tried to send a keepalive probe. This caused megatools to try to reconnect, which means that this problem is somewhat solved as well.

Thanks for your prompt and informative answer! I have attached a patch for http.c for if you wish to merge it.



‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
On Thursday, March 11, 2021 10:31 AM, Ondřej Jirman <megous@megous.com> wrote:

> Hi,
>
> On Thu, Mar 11, 2021 at 02:18:48AM +0000, Space wrote:
>
> > I noticed that when my connection drops (switching locations on a VPN or
> > internet goes out) that megatools' download speed goes down to 0 bytes/sec but
> > never recovers after the internet is back. I don't work with C often but if
> > you can point me to where you think the problem would be I can try to fix it
> > and perhaps try to merge the changes with your repo.
>
> mega servers probably time out after your machine drops off the network and kill
> the connection on their side instead of waiting for your machine to be available
> again, but your machine will not know, because it doesn't send any packets out,
> that would trigger TCP reset. So it just waits for more packets that will never
> arrive.
>
> This is fairly normal behavior in this situation for TCP sockets.
>
> One fix may be to enable keepalive packets on the socket.
>
> Curl probably has some options to do that. You can try enabling it in the
> http.c file on the data connections:
>
> https://curl.se/libcurl/c/CURLOPT_TCP_KEEPALIVE.html
>
> It should help.
>
> regards,
> o.