Network Engineering How can I introduce a delay into network connections without dropping the connection entirely?
I'm a software developer and I'm using some C++ library to access a database. I want to test some aspects related to the handling of timeouts and stuck connections. While I can mock certain stuff, I also want to test how the real application is going to handle "hangups", i.e. situations where the connection is not "dead" but is not responding for a period of time, either.
So my question is: on a Linux machine, is it possible and if yes, how, to put a network connection into a state where a library that wants to connect to a server on the Internet (I can set up the program to use a local IP as well) will not immediately "figure out" that there's no Internet connectivity, but will remain stuck for a (ideally long, in the order of seconds or longer) while?
Use the tc
traffic shaper, specifically its "netem" module.
- https://jvns.ca/blog/2017/04/01/slow-down-your-internet-with-tc/
- https://wiki.linuxfoundation.org/networking/netem
Alternatively: Add a high-priority firewall rule using iptables -I
that just drops packets to/from the test destination, wait a few seconds, then remove the rule.