[cdc_rsync] Fix issue with IPV6 localhosts (#93)

Fixes an issue with port forwarding when localhost on the remote
system maps to the IPV6 localhost. In that case the server would time
out on accept() since it creates an IPV4 socket, so the connection
is never established.

Also allows passing in port 0, so that it will auto-detect an
available port. This will be used in a future CL to remove the
necessity of running netstat/ss.
This commit is contained in:
Lutz Justen
2023-02-14 11:09:03 +01:00
committed by GitHub
parent fcc4cbc3f3
commit 5fd86e4625
4 changed files with 109 additions and 19 deletions
+6 -4
View File
@@ -24,6 +24,7 @@
#include "common/log.h"
#include "common/path.h"
#include "common/status.h"
#include "common/status_macros.h"
#include "common/stopwatch.h"
#include "common/threadpool.h"
#include "common/util.h"
@@ -295,10 +296,11 @@ absl::Status CdcRsyncServer::Run(int port) {
socket_finalizer_ = std::make_unique<SocketFinalizer>();
socket_ = std::make_unique<ServerSocket>();
status = socket_->StartListening(port);
if (!status.ok()) {
return WrapStatus(status, "Failed to start listening on port %i", port);
}
int new_port;
ASSIGN_OR_RETURN(new_port, socket_->StartListening(port),
"Failed to start listening on port %i", port);
assert(port != 0);
assert(port == new_port);
LOG_INFO("cdc_rsync_server listening on port %i", port);
// This is the marker for the client, so it knows it can connect.