Close socket properly before the next iteration

This avoid the errors `[Errno 106] Transport endpoint is already
connected` which are due to connections kept in TIME_WAIT state.

We don't use socket.SO_REUSEADDR as it would make the first connection
a special case compared to the following ones.
This commit is contained in:
Rafa de la Torre
2019-11-13 12:25:41 +01:00
parent 5897d8a9cb
commit 4b9c048235

View File

@@ -161,6 +161,8 @@ AS $$
except (socket.timeout, OSError, socket.error), ex:
plpy.warning('could not connect to server %s:%d, %s' % (host, port, str(ex)))
n_errors += 1
finally:
s.close()
t_connect = (t_stop - t_start) * 1000.0
plpy.debug('TCP connection %s:%d time=%.2f ms' % (host, port, t_connect))