sony / nmos-cpp

An NMOS (Networked Media Open Specifications) Registry and Node in C++ (IS-04, IS-05)
Apache License 2.0
136 stars 79 forks source link

ASIO Listen Error in Linux when Registry restarted. #320

Closed RichardNutman closed 1 year ago

RichardNutman commented 1 year ago

I just built latest code and was testing the Registry application it in a Docker container. I started getting web-socket connection refused errors.

In the log there is this printed out; 2023-03-21 10:19:12.035: info: 140339052975936: Preparing for connections 2023-03-21 10:19:12.038: info: 140339019933440: asio listen error: system:98 (Address already in use) 2023-03-21 10:19:12.038: info: 140339019933440: listening with IPv6 failed; retrying with IPv4 only 2023-03-21 10:19:12.038: info: 140339019933440: asio listen error: system:98 (Address already in use) 2023-03-21 10:19:12.038: info: 140339052975936: Ready for connections

It seems if we just restart the Docker container, the Registry restarts too quickly and is unable to listen on the specific ports as the OS hasn't released them yet.

Using this config file; { "pri": 0, "logging_level": 0, "allow_invalid_resources": false, "http_trace": false, "label": "NMOS Registry", "http_port": 4041, "query_ws_port": 8011, "registration_expiry_interval": 12, "validate_certificates": false }

Any reason why we couldn't add in the ASIO set_reuse_addr() function to get around this ?

garethsb commented 1 year ago

In websocket_listener? Yes, that sounds sensible, and would mirror that http_listener already does this.

Insert set_reuse_addr after start_perpetual... https://github.com/sony/nmos-cpp/blob/17f1b8b3194f47d81b0be614276be96ade81b760/Development/cpprest/ws_listener_impl.cpp#L326

RichardNutman commented 1 year ago

Yes, that location works. Initial testing shows no more connection issues to the WS on container restarts.