Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LockPort hangs the application if port is unusable #7

Open
yusufozturk opened this issue Nov 28, 2022 · 1 comment
Open

LockPort hangs the application if port is unusable #7

yusufozturk opened this issue Nov 28, 2022 · 1 comment
Labels
bug Something isn't working

Comments

@yusufozturk
Copy link

yusufozturk commented Nov 28, 2022

If the default port 2978 is not available on the system, then LockPort stucks in infinite for loop.

leakless/leakless.go

Lines 131 to 138 in 9bcba10

for {
var err error
l, err = net.Listen("tcp", fmt.Sprintf(":%d", port))
if err == nil {
break
}
time.Sleep(time.Duration(rand.Intn(100)) * time.Millisecond)
}

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.

@ysmood ysmood added the bug Something isn't working label Nov 29, 2022
@ysmood
Copy link
Owner

ysmood commented Dec 6, 2022

Agree, we should at least provide a timeout for this function, could you help to make a PR for it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants