make sure all workers bind to the same address when using
Summary:
This is a bug where each worker can potentially bind to different address if no
address is supplied
MODIFY
quic/server/QuicServer.cpp
quic/server/QuicServer.cpp
@@ -184,11 +184,11 @@ void QuicServer::bindWorkersToSocket(
const folly::SocketAddress& address,
const std::vector<folly::EventBase*>& evbs) {
auto numWorkers = evbs.size();
+ CHECK(!initialized_);
+ boundAddress_ = address;
for (size_t i = 0; i < numWorkers; ++i) {
auto workerEvb = evbs[i];
- workerEvb->runImmediatelyOrRunInEventBaseThreadAndWait(
- [address,
- self = this->shared_from_this(),
+ workerEvb->runInEventBaseThreadAndWait([self = this->shared_from_this(),
workerEvb,
numWorkers,
processId = processId_,
@@ -207,21 +207,27 @@ void QuicServer::bindWorkersToSocket(
}
// dup the takenover socket on only one worker and bind the rest
if (takeoverOverFd >= 0) {
- VLOG(4) << "Setting dup()'ed fd for address=" << address
- << " on workerId=" << (int)worker->getWorkerId();
workerSocket->setFD(
folly::NetworkSocket::fromFd(::dup(takeoverOverFd)),
// set ownership to OWNS to allow ::close()'ing of of the fd
// when this server goes away
folly::AsyncUDPSocket::FDOwnership::OWNS);
worker->setSocket(std::move(workerSocket));
+ if (idx == 0) {
+ self->boundAddress_ = worker->getAddress();
+ }
+ VLOG(4) << "Set up dup()'ed fd for address=" << self->boundAddress_
+ << " on workerId=" << (int)worker->getWorkerId();
} else {
- VLOG(4) << "No valid takenover fd found for address=" << address
- << ". binding on worker=" << worker
+ VLOG(4) << "No valid takenover fd found for address="
+ << self->boundAddress_ << ". binding on worker=" << worker
<< " workerId=" << (int)worker->getWorkerId()
<< " processId=" << (int)processId;
worker->setSocket(std::move(workerSocket));
- worker->bind(address);
+ worker->bind(self->boundAddress_);
+ if (idx == 0) {
+ self->boundAddress_ = worker->getAddress();
+ }
}
if (idx == (numWorkers - 1)) {
VLOG(4) << "Initialized all workers in the eventbase";
@@ -614,7 +620,7 @@ void QuicServer::addTransportFactory(
const folly::SocketAddress& QuicServer::getAddress() const {
CHECK(initialized_) << "Quic server is not initialized. "
<< "Consider calling waitUntilInitialized() before this ";
- return workers_[0]->getAddress();
+ return boundAddress_;
}
void QuicServer::setListeningFDs(const std::vector<int>& fds) {

MODIFY
quic/server/QuicServer.h
quic/server/QuicServer.h
@@ -367,6 +367,8 @@ class QuicServer : public QuicServerWorker::WorkerCallback,
std::unique_ptr<ConnectionIdAlgo> connIdAlgo_;
// Used to override certain transport parameters, given the client address
TransportSettingsOverrideFn transportSettingsOverrideFn_;
+ // address that the server is bound to
+ folly::SocketAddress boundAddress_;
};
} // namespace quic

make sure all workers bind to the same address when using

Summary:
This is a bug where each worker can potentially bind to different address if no
address is supplied

Reviewed By: mjoras

Differential Revision: D19533888

fbshipit-source-id: 6f1258f09564d44ebb9843789d441c1fdecbdacc