I’m trying to debug an apparently low level intermittent ConnectionError (likely happening at the TCP layer).
For this I’ve built a multiprocessed program spamming a remote site and catching the relevant error, and am monitoring the traffic via wireshark with the goal of capturing a full faulty TCP conversation.
It’s difficult to match an error with a specific TCP conversation in wireshark as there’s a really high throughput (that error is very infrequent so I need a lot of them to see it happen once!), so I’d like to record the client side port used in the connection for each request (or at least for failing ones) so I can log this when there’s an error and find the culprit TCP stream.
This solution using socket.fromfd was the closest I found, except of course it doesn’t work here because the exception happens while making the request so r
doesn’t exist in case of error and I can’t access the fd.
Is there some way to get/create the socket before sending the request so I can know which client port will be used? Or some hook maybe in urllib3 after the socket creation but before the TCP conversation starts, where I can access/log it?