Search code examples
pythonhttptcp

HTTP Response code when there is a error in TCP layer


I have a python function which performs a HTTP call on a server to perform business logic. Http call to the server in the python function is implemented with retry mechanism using following library. This library helps to retry http requests based on Http status code passed in 'status_forcelist'. I am bit unsure of HTTP stats code to exapect if there is a TCP error in between and possible http status code that can be expected due to error in network layer(s) which can be additionally added to the 'status_forcelist' list.

In case there is no Http status code received but exception is thrown, how should retiaries be handled in that case


Solution

  • In fact, in a network stack, each protocol has a level of responsability and higher protocols just assume that lower levels could do their job. For example TCP guarantees that all packets are recieved in the correct order but do not really care for the content of a packet: a lower level protocol (HDLC on ethernet) should have taken care of it. And in fact, either a TCP packet is correct at the lower lever or it would not be delivered and the resend part of TCP would ask the sender to send it again. If it cannot be recovered the TCP connection will be aborted.

    At a higher level (HTTP) it will give a connect or read error. And those are explicitely handled by the urllib3 module, which allows the programmer to decide the number of retries per connect, read or protocol error (and/or total errors) along with the connect and read (or total) timeout.