CSD - Bind address error
Sometimes CSD quits with message "Adress already in use..."
Ldv-core will check address and then run csd. But between Ldv-core checks and
starting CSD adress is unused.
It may be possible if running more than one ldv-tools and second CSD starts before the first.
1. ldv-core1 - find_free_address - 8080 -> starting csd1 with 8080
2. ldv_core2 - find_free_address - 8080 -> starting csd2 with 8080
3. csd2 - try to bind address 8080 - Ok
4. csd1 - try to bind address 8080 - failed because adress 8080 already busy (by csd2)
#1 Updated by Pavel Shved about 8 years ago
A way to do it without races is like this. Do not first check, then start server with the port found. Just start server at once, and if it fails with "already in use" error, attempt to start it on the next port. This way you'll start a server without any races.
Then the server somehow informs the calling program about the port it's managed to bind to (via standard output, or a pid-based temp file), and the calling program connects to that port.
To make a workaround, you might just sleep for a random time before checking if the port's in use.
#3 Updated by Pavel Shved about 8 years ago
Alexandr Strakh wrote:
I will check the STDERR for a message "address already in use" in case of crash CSD. And then try to run CSD with new address.
Ok, but make sure you'll still show other error messages to user. Don't forget to add comments about that!
#9 Updated by Alexey Khoroshilov about 7 years ago
The right solution is proposed above:
Pavel Shved wrote:
if ldv-core was the server, and CSD was the client, not vice versa...
For now, trying to reduce probability of the race, I have committed a patch to select random ports from 8080 to 8099 instead of predefined sequence starting from 8080.