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

restarting pigpiod result in "bind to port 8888 failed (Address already in use)" #298

Closed
janvda opened this issue Oct 4, 2019 · 9 comments
Assignees
Labels
Milestone

Comments

@janvda
Copy link

janvda commented Oct 4, 2019

I have defined a docker service (in balena) that runs the pigpiod daemon.
The problem is that when I try to restart that service, I am getting the following error:

04.10.19 08:35:11 (+0200)  pigpiod  2019-10-04 06:35:11 initInitialise: bind to port 8888 failed (Address already in use)
04.10.19 08:35:11 (+0200)  pigpiod  Can't initialise pigpio library

I strongly think that the operating system is not allowing immediately to rebind to the same port. So you should wait for TIME_WAIT period before a process again can bind to the same port.

@janvda
Copy link
Author

janvda commented Oct 4, 2019

For more details see also janvda/balena-node-red#1

@janvda
Copy link
Author

janvda commented Oct 4, 2019

This issue can be resolved by using the socket option SO_REUSEADDR (see https://stackoverflow.com/questions/21967311/linux-refuse-to-open-listening-port-from-localhost).

So it would be nice if you would consider setting this socket option.

@guymcswain
Copy link
Collaborator

I checked the code. SO_REUSEADDR is being used.

@guymcswain
Copy link
Collaborator

Please retest and provide more information if its still an issue. I tried to follow your links but found evidence the problem may have been resolved.

@maxnet
Copy link
Contributor

maxnet commented Jan 4, 2020

You currently have:

            int opt;
            setsockopt(fdSock, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt));

But think it should be instead:

            int opt = 1;
            setsockopt(fdSock, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt));

@guymcswain
Copy link
Collaborator

@maxnet, You are correct! Thank you for reviewing the code and finding this oversight. Meanwhile, I need to bolster the testing around the network features.

@guymcswain guymcswain added bug and removed Retest labels Jan 5, 2020
@guymcswain guymcswain assigned guymcswain and unassigned janvda Jan 5, 2020
@guymcswain guymcswain added this to the Add Test milestone Jan 5, 2020
@guymcswain
Copy link
Collaborator

@janvda , please retest with the patch for this issue in the 'develop' branch of this repo.

@dachshund-digital
Copy link

What this fix implemented? In version 78 or 79? I just encountered it on Pi OS buster Debian 10 (fully patched as of today). Happen to be running 78.

May 03 00:12:29 pi3modelb0 pigpiod[32482]: 2021-05-03 00:12:29 initInitialise: bind to port 8888 failed (Cannot assign requested address)
May 03 00:12:29 pi3modelb0 pigpiod[32482]: Can't initialise pigpio library
M

@guymcswain
Copy link
Collaborator

Yes both 78, 79. It was implemented in earlier version but don't recall which off the top of my head.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants