-
-
Save jolynch/90033c2b10ab8280859c8cfe352503cd to your computer and use it in GitHub Desktop.
TCP_USER_DELAY Testing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import socket | |
import sys | |
import time | |
if len(sys.argv) > 1: | |
TIMEOUT = int(sys.argv[1]) | |
else: | |
TIMEOUT = 5000 | |
HOST="127.0.0.1" | |
PORT=12345 | |
s = socket.socket( | |
socket.AF_INET, socket.SOCK_STREAM) | |
s.setsockopt( | |
socket.IPPROTO_TCP, socket.TCP_USER_TIMEOUT, TIMEOUT | |
) | |
s.connect((HOST, PORT)) | |
print( | |
("Sleeping 10s for you to partition the network" | |
"on {0}:{1}").format( | |
HOST, PORT | |
) | |
) | |
time.sleep(10) | |
print("Attempting to send on socket, waiting for an exception") | |
print("TCP_USER_TIMEOUT={0}".format(TIMEOUT)) | |
start = time.time() | |
while True: | |
try: | |
s.send(b'hi\n') | |
time.sleep(1) | |
except Exception as e: | |
print('Detected partition!') | |
print(e) | |
break | |
print("Partition healed after {}s".format(time.time() - start)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ uname -r | |
4.13.0-19-generic | |
$ python 14358_repro.py 5000 | |
Sleeping 10s for you to partition the networkon 127.0.0.1:12345 | |
Attempting to send on socket, waiting for an exception | |
TCP_USER_TIMEOUT=5000 | |
Detected partition! | |
[Errno 110] Connection timed out | |
Partition healed after 7.0073323249816895s | |
$ python 14358_repro.py 10000 | |
Sleeping 10s for you to partition the networkon 127.0.0.1:12345 | |
Attempting to send on socket, waiting for an exception | |
TCP_USER_TIMEOUT=10000 | |
Detected partition! | |
[Errno 110] Connection timed out | |
Partition healed after 14.011962413787842s | |
$ python 14358_repro.py 30000 | |
Sleeping 10s for you to partition the networkon 127.0.0.1:12345 | |
Attempting to send on socket, waiting for an exception | |
TCP_USER_TIMEOUT=30000 | |
Detected partition! | |
[Errno 110] Connection timed out | |
Partition healed after 54.052321434020996s |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pkill -9 -f "nc -l 12345" && sudo iptables -F OUTPUT; nc -l 12345 & |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# To partition the network | |
sudo iptables -A OUTPUT -p tcp -d 127.0.0.1 --dport 12345 -j DROP |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment