From code review to TCP congestion control

5 min readFeb 18, 2024

The data transmission solution is not for error handling

The code review

“Bro, can you help to review this link again? I have fixed your comment ‘add some error handling here’” A teammate asked.

“Sure, let me take a look. could you explain why ‘smart_sleep’ could help handle the error”? I asked.

def smart_sleep(error_code):
tried = 1
max_try = 1024 # try 10 times
sleep_time = 500
while tried < max_try:
error_code = service_call(...)
if error_code == 0: # all good
if error_code == 500:
tried *= 2

“Okay. As you can see I added retry when calling the service, also I added sleep time based on the error code, if all good then no sleep otherwise I will retry longer and longer time,” he said.

“Okay but why do you sleep longer and longer time for the error?” I asked.

“Because this idea is from ‘tcp congestion control’ — slow start, the error should be due to xxx which is something known and it could happen so I retry a few times it may work and I do not want to load the server so I put sleep longer and longer,” he said.

“Well bro, that is for a different issue. but let’s clarify error handling first. when an error happens, if it is something not expected or unknown to this code layer, just raise it up; if it is expected like you mentioned ‘common error’…




A channel which focusing on developer growth and self improvement