Pulling out Network Cable / Disabling Network Adaptor
It is a common misconception that pulling out a network cable or disabling a network adapter is an accurate way to simulate a disconnection. When you pull out a cable this affects the physical layer (layer 1) and Ethernet (layer 2) will notice this disruption almost immediately. TCP (layer 4) will not notice this by design. Under these circumstances the TCP connection will not be terminated. TCP is designed to overcome and work around failures in the physical network, even deliberate ones. Furthermore these efforts are deliberately invisible from the outside. Protocols layered on top of TCP can use heartbeats to assert that the connection remains open; Diffusion provides system pings and the liveness monitor for this purpose. However, these cannot react at the same time as the physical break in the connection as this is hidden by the TCP layer.
Note: Windows 10 is known to immediately tear down TCP connections when the physical connection is severed. In Windows 7 and 8, TCP connections are not severed under the same circumstances.
Simulating disconnection with a proxy
To simulate a communication error, we use a proxy between the client and the server.
- Start Diffusion. (By default it uses port 8080)
- Set the proxy to listen on a different port (for example, 9090) and redirect the connection to 8080
- Connect the client through the proxy on port 9090.
- Kill the proxy.
- Start the proxy.
- Reconnect the client.