spenceforce / pdb-attach

A python debugger that can attach to running processes.
BSD 3-Clause "New" or "Revised" License
33 stars 1 forks source link

Dynamically port assignment in the multiprocessing systems #26

Closed Littlenightingale closed 10 months ago

Littlenightingale commented 10 months ago

Pdb_attach is not resistant to race conditions - in the short time between getting the free port number and using this port other process may use this port. I'm wondering if it is any possibility to dynamically select a port by the IO system and fullfily ensure that the port is free.

spenceforce commented 10 months ago

It’s always going to be subject to that. Especially since the port number is supplied by the user. The closest thing I’ve seen to what you describe is from python test code for the socket module which pdb-attach uses in its own tests, but this is also subject to race conditions since there’s no guarantee of an atomic operation that gets a free port and binds that port in python.