Skip to content

Commit

Permalink
Test SeattleTestbed#52, issues with socket timeout
Browse files Browse the repository at this point in the history
This patches `emulcomm` to provide some insight into the mechanics
of too-large socket timeouts, and provides a unit test to trigger
the instrumentation.
  • Loading branch information
aaaaalbert committed Sep 4, 2017
1 parent 4d53f71 commit af748b7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
3 changes: 3 additions & 0 deletions emulcomm.py
Original file line number Diff line number Diff line change
Expand Up @@ -1162,16 +1162,19 @@ def _timed_conn_initialize(localip,localport,destip,destport, timeout):
# Get a TCP socket bound to the local ip / port
sock = _get_tcp_socket(localip, localport)
sock.settimeout(timeout)
print "Set the socket timeout to", sock.gettimeout()

try:
# Try to connect until we timeout
connected = False
while nonportable.getruntime() - starttime < timeout:
try:
sock.connect((destip, destport))
print nonportable.getruntime(), "This should never print"
connected = True
break
except Exception, e:
print nonportable.getruntime(), "Exception is", repr(e)
# Check if we are already connected
if _is_already_connected_exception(e):
connected = True
Expand Down
18 changes: 18 additions & 0 deletions testsV2/ut_repyv2api_openconnectionhugetimeout.r2py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"""
Test for SeattleTestbed/repy_v2#52, openconnection timeout issues
"""
timeout = 100
start_time = getruntime()
log("Timeout", timeout, "Start time:", str(start_time), "\n")

try:
openconnection(gethostbyname("gmail.com"), 63100, getmyip(), 63100, timeout)
except TimeoutError:
pass
except Exception, e:
log(getruntime(), "Error raised: ", repr(e))

end_time = getruntime()
log("End time: " + str(end_time))
log("Elapsed time: " + str(end_time - start_time))
log("\n")

0 comments on commit af748b7

Please sign in to comment.