What I don't understand (and which your suggested fix has reminded me to
ask!) is why the next received packet does not result in the delayed ACK
being dispatched. The reason the suggested fix works, is that tcp_ack()
gets called twice for each received packet (once in tcp_receive() and
once in tcp_recved()). Because we ensure that there are no more than
two delayed acknowledgements, the second call sends an ack immediately.
However, this shouldn't be necessary (and I can see now why the check in
tcp_recved() is there - it's just doing a window update rather than a
full ACK), as if the stack continues to receive data, the next received
packet will cause tcp_ack() to be called, and an ACK dispatched then.
i.e. If a stack is constantly receiving data, ACKs should never need to
wait for a timer to expire before they are sent.
The only way I could see this breaking down is if the TCP segment size
is similar to the TCP window size. Then, a single segment will close
the whole window, needing an ACK to open it again before any other
segments can be sent, but the ACK is delayed waiting for another
segment. If that is the cause of the problem, I would class it as a
misconfiguration (the max segment size should not be as large as the
window) rather than a bug in lwIP.
Could you check what your TCP_WND and TCP_MSS are set to?