[PATCH] tester: Avoid TFTP race condition

Kinsey Moore kinsey.moore at oarcorp.com
Mon May 17 18:29:10 UTC 2021


The u-boot TFTP client will fail a fully completed file retrieval if the
final ACK gets an ICMP response that the port is unavailable which can
occur if the port is closed before the ACK arrives from the client. This
change causes the TFTP server to wait for the final ACK before closing
the socket and prevents transfers from failing due to the race
condition.
---
 tester/rt/tftpserver.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tester/rt/tftpserver.py b/tester/rt/tftpserver.py
index d733301..46b594f 100644
--- a/tester/rt/tftpserver.py
+++ b/tester/rt/tftpserver.py
@@ -418,8 +418,6 @@ class udp_handler(socketserver.BaseRequestHandler):
                             ' < ' +
                             session.decode(client_ip, client_port, response))
                     sock.sendto(response, (client_ip, client_port))
-                    if session.finished:
-                        break
                     try:
                         data, address = sock.recvfrom(2 + 2 +
                                                       session.get_block_size())
@@ -438,6 +436,8 @@ class udp_handler(socketserver.BaseRequestHandler):
                             log.trace('] tftp: %d: receive: %s: error: %s' \
                                       % (index, client, serr))
                         return
+                    if session.finished:
+                        break
                     response = session.process(address[0], address[1], data)
         except error.general as gerr:
             self._notice('] tftp: %dd: error: %s' % (index, gerr))
-- 
2.20.1



More information about the devel mailing list