You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While reviewing the get_routable_ip_to function in torchx/apps/serve/serve.py, I noticed that the socket is directly closed using s.close(), without calling shutdown() beforehand.
defget_routable_ip_to(addr: str) ->str:
""" get_routable_ip_to opens a dummy connection to the target HTTP URL and returns the IP address used to connect to it. """parsed=urlparse(addr)
try:
s=socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect((parsed.hostname, parsed.portor80))
returns.getsockname()[0]
finally:
s.close()
Question
Would there be any potential downsides or benefits to adding a shutdown(socket.SHUT_RDWR) call before closing the socket in the get_routable_ip_to function?
Possible Benefits
Ensures that all pending data is properly discarded before closing, particularly if the socket is still in a half-open state.
Prevents potential issues with lingering resources and improves resource management.
Aligns with best practices for socket cleanup.
Reference
The Python socket documentation states:
"close() releases the resource associated with a connection but does not necessarily close the connection immediately. If you want to close the connection in a timely fashion, call shutdown() before close()." link
Looking forward to your thoughts!
Thanks!
The text was updated successfully, but these errors were encountered:
Description:
While reviewing the get_routable_ip_to function in torchx/apps/serve/serve.py, I noticed that the socket is directly closed using s.close(), without calling shutdown() beforehand.
Question
Would there be any potential downsides or benefits to adding a shutdown(socket.SHUT_RDWR) call before closing the socket in the get_routable_ip_to function?
Possible Benefits
Reference
The Python socket documentation states:
"close() releases the resource associated with a connection but does not necessarily close the connection immediately. If you want to close the connection in a timely fashion, call shutdown() before close()." link
Looking forward to your thoughts!
Thanks!
The text was updated successfully, but these errors were encountered: