Opened 7 years ago

Closed 7 years ago

#8272 closed defect (fixed)

Connection reset when uploading firmware through LuCI

Reported by: dharding@… Owned by: jow
Priority: high Milestone: Backfire 10.03.1
Component: base system Version: Backfire 10.03.1 RC3
Keywords: uhttpd Cc:


A few weeks ago I noticed that whenever I would attempt to upload new firmware using the LuCI web interface, the HTTP connection would be reset by the router, causing the upload to fail.

I did some debugging of uhttpd and discovered that while executing the I/O loop in uh_cgi_loop, a call to recv was generating an ETIMEDOUT error before the loop had received all the expected data (and the amount of data it would receive before the error occurred varied between runs).

I did a packet capture with Wireshark to see what was actually going over the wire, and the web browser was sending all of the data correction, but about half a second after the web browser sent the last packet of the POST request, a reset packet was being sent from the router.

Unsure why this was happening, I ran a bisection, and landed on r22962 ([backfire] merge r22630, r22692, r22805). Examining the diffs, I noticed this change enabled TCP keep-alives, which I suspected might be to blame. Sure enough, turning them off caused the problem to go away.

However, without TCP keep-alives, uhttpd is susceptible to getting hung up in a call to recv if for whatever reason the browser sent an incomplete request. To address this problem, I added a call to select in uh_tcp_recv, before the call to recv, allowing a time-out to occur if no data arrives in a timely manner (mirroring what is done in uh_tcp_send when sending data).

I am attaching a patch with these changes. There may be a problem somewhere with the TCP keep-alive mechanism, since I cannot see any reason why the connection should have been considered dead (as I mentioned, the reset packet was received by the browser less than a second after the last data packet was sent from the browser). I did not try to investigate that issue at all, but it might be worth looking into if there really is a problem that could affect other programs using TCP keep-alive.

Attachments (1)

uhttpd-fix-connection-reset-when-uploading-firmare-t.patch (3.7 KB) - added by dharding@… 7 years ago.
[uhttpd] fix connection reset when uploading firmare through LuCI

Download all attachments as: .zip

Change History (3)

Changed 7 years ago by dharding@…

[uhttpd] fix connection reset when uploading firmare through LuCI

comment:1 Changed 7 years ago by jow

  • Owner changed from developers to jow
  • Status changed from new to accepted

comment:2 Changed 7 years ago by jow

  • Resolution set to fixed
  • Status changed from accepted to closed

I incorperated your patch in r24952 and made the tcp keep-alive tunable through a config option / command line flag. Thanks a lot for your input!

Add Comment

Modify Ticket

as closed .
The resolution will be deleted. Next status will be 'reopened'.

E-mail address and user name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.