They prevent the application from waiting indefinitely for a server response.
Connection timeouts are essential because they limit how long an application waits when attempting to establish a connection to a server. Without them, if a server is unreachable or unresponsive, the application could hang indefinitely, potentially exhausting resources. For instance, when an e-commerce site tries to connect to an external shipping API, setting a timeout ensures that the application quickly moves on if the API is down.
Additional Notes
Why are connection timeouts crucial in HTTP clients?