leakless
leakless copied to clipboard
LockPort hangs the application if port is unusable
If the default port 2978 is not available on the system, then LockPort stucks in infinite for loop.
https://github.com/ysmood/leakless/blob/9bcba10de12281baf8fdd457088d121e0160b74b/leakless.go#L131-L138
In my case, I keep getting:
listen tcp 127.0.0.1:2978: bind: An attempt was made to access a socket in a way forbidden by its access permissions.
This is a problem with Windows. It reserves and blocks the ports if you have Docker or Hyper-V. But this port might be also in use by system. So it would be better to return an error, so users can understand why the application is hanged.
Maybe a try limit would be also good. For example try to listen port 3 times and then return error if it doesn't work. Or maybe allow an ability to switch automatically to .Leakless(false) for go-rod. (I'm not sure about this)
Edit: Oh I see, you use this port for cross-process locking. I'm not sure in this case. Maybe we can check returned error.
Agree, we should at least provide a timeout for this function, could you help to make a PR for it?