From 77289015b244caadd4d54acdee424fc83c754c7b Mon Sep 17 00:00:00 2001 From: Bernard Normier Date: Wed, 23 Oct 2024 14:38:39 -0400 Subject: [PATCH] Specify connection when creating Allocation/Admin session for Glacier2 --- cpp/src/IceGrid/AdminSessionI.cpp | 20 +++++++++++++------- cpp/src/IceGrid/AdminSessionI.h | 7 +++++-- cpp/src/IceGrid/InternalRegistryI.cpp | 10 ++++++++-- cpp/src/IceGrid/ReapThread.cpp | 2 +- cpp/src/IceGrid/ReapThread.h | 2 +- cpp/src/IceGrid/SessionI.cpp | 17 ++++++++++------- cpp/src/IceGrid/SessionI.h | 6 ++++-- 7 files changed, 42 insertions(+), 22 deletions(-) diff --git a/cpp/src/IceGrid/AdminSessionI.cpp b/cpp/src/IceGrid/AdminSessionI.cpp index aa0ef6c578e..7646a9fdbf0 100644 --- a/cpp/src/IceGrid/AdminSessionI.cpp +++ b/cpp/src/IceGrid/AdminSessionI.cpp @@ -459,12 +459,15 @@ AdminSessionFactory::AdminSessionFactory( } Glacier2::SessionPrx -AdminSessionFactory::createGlacier2Session(const string& sessionId, const optional& ctl) +AdminSessionFactory::createGlacier2Session( + const string& sessionId, + const optional& ctl, + const Ice::ConnectionPtr& con) { assert(_servantManager); auto session = createSessionServant(sessionId); - auto proxy = session->_register(_servantManager, nullptr); + auto proxy = session->_register(_servantManager, con); if (ctl) { @@ -489,7 +492,7 @@ AdminSessionFactory::createGlacier2Session(const string& sessionId, const option // We can't use a non-0 timeout such as the Glacier2 session timeout. As of Ice 3.8, heartbeats may not be sent // at all on a busy connection. Furthermore, as of Ice 3.8, Glacier2 no longer "converts" heartbeats into // keepAlive requests. - _reaper->add(make_shared>(_database->getTraceLevels()->logger, session), 0s); + _reaper->add(make_shared>(_database->getTraceLevels()->logger, session), 0s, con); return Ice::uncheckedCast(proxy); } @@ -508,15 +511,18 @@ AdminSessionFactory::getTraceLevels() const AdminSessionManagerI::AdminSessionManagerI(const shared_ptr& factory) : _factory(factory) {} optional -AdminSessionManagerI::create(string userId, optional ctl, const Ice::Current&) +AdminSessionManagerI::create(string userId, optional ctl, const Ice::Current& current) { - return _factory->createGlacier2Session(std::move(userId), std::move(ctl)); + return _factory->createGlacier2Session(std::move(userId), std::move(ctl), current.con); } AdminSSLSessionManagerI::AdminSSLSessionManagerI(const shared_ptr& factory) : _factory(factory) {} optional -AdminSSLSessionManagerI::create(Glacier2::SSLInfo info, optional ctl, const Ice::Current&) +AdminSSLSessionManagerI::create( + Glacier2::SSLInfo info, + optional ctl, + const Ice::Current& current) { string userDN; if (!info.certs.empty()) // TODO: Require userDN? @@ -535,5 +541,5 @@ AdminSSLSessionManagerI::create(Glacier2::SSLInfo info, optionalcreateGlacier2Session(std::move(userDN), std::move(ctl)); + return _factory->createGlacier2Session(std::move(userDN), std::move(ctl), current.con); } diff --git a/cpp/src/IceGrid/AdminSessionI.h b/cpp/src/IceGrid/AdminSessionI.h index 26baac27cb3..8c22877b1a9 100644 --- a/cpp/src/IceGrid/AdminSessionI.h +++ b/cpp/src/IceGrid/AdminSessionI.h @@ -86,8 +86,11 @@ namespace IceGrid const std::shared_ptr&, const std::shared_ptr&); - Glacier2::SessionPrx - createGlacier2Session(const std::string&, const std::optional&); + Glacier2::SessionPrx createGlacier2Session( + const std::string& sessionId, + const std::optional& ctl, + const Ice::ConnectionPtr& con); + std::shared_ptr createSessionServant(const std::string&); const std::shared_ptr& getTraceLevels() const; diff --git a/cpp/src/IceGrid/InternalRegistryI.cpp b/cpp/src/IceGrid/InternalRegistryI.cpp index 5dbe7c17a72..ba8e3ee32f9 100644 --- a/cpp/src/IceGrid/InternalRegistryI.cpp +++ b/cpp/src/IceGrid/InternalRegistryI.cpp @@ -62,7 +62,10 @@ InternalRegistryI::registerNode( try { auto session = NodeSessionI::create(_database, std::move(*node), info, _nodeSessionTimeout, load); - _reaper->add(make_shared>(logger, session), _nodeSessionTimeout); + + // nullptr for the connection parameter, meaning the reaper won't destroy the session if the connection is + // closed. + _reaper->add(make_shared>(logger, session), _nodeSessionTimeout, nullptr); return session->getProxy(); } catch (const Ice::ObjectAdapterDestroyedException&) @@ -93,7 +96,10 @@ InternalRegistryI::registerReplica( try { auto s = ReplicaSessionI::create(_database, _wellKnownObjects, info, std::move(*prx), _replicaSessionTimeout); - _reaper->add(make_shared>(logger, s), _replicaSessionTimeout); + + // nullptr for the connection parameter, meaning the reaper won't destroy the session if the connection is + // closed. + _reaper->add(make_shared>(logger, s), _replicaSessionTimeout, nullptr); return s->getProxy(); } catch (const Ice::ObjectAdapterDestroyedException&) diff --git a/cpp/src/IceGrid/ReapThread.cpp b/cpp/src/IceGrid/ReapThread.cpp index 86fca1ffc77..3ea92ded413 100644 --- a/cpp/src/IceGrid/ReapThread.cpp +++ b/cpp/src/IceGrid/ReapThread.cpp @@ -141,7 +141,7 @@ ReapThread::add(const shared_ptr& reapable, chrono::seconds timeout, c } // NOTE: registering a reapable with a 0s timeout is allowed. The reapable is reaped only when the reaper thread is - // shutdown or the connection is closed. + // shutdown or the connection is closed (when connection is not null). // // 10 seconds is the minimum permissable timeout (for non-zero timeouts). diff --git a/cpp/src/IceGrid/ReapThread.h b/cpp/src/IceGrid/ReapThread.h index 076bb41794e..075940afd4e 100644 --- a/cpp/src/IceGrid/ReapThread.h +++ b/cpp/src/IceGrid/ReapThread.h @@ -69,7 +69,7 @@ namespace IceGrid void terminate(); void join(); - void add(const std::shared_ptr&, std::chrono::seconds, const Ice::ConnectionPtr& = nullptr); + void add(const std::shared_ptr&, std::chrono::seconds, const Ice::ConnectionPtr&); void connectionClosed(const Ice::ConnectionPtr&); diff --git a/cpp/src/IceGrid/SessionI.cpp b/cpp/src/IceGrid/SessionI.cpp index 7e6084dc66a..6e3d050656c 100644 --- a/cpp/src/IceGrid/SessionI.cpp +++ b/cpp/src/IceGrid/SessionI.cpp @@ -277,12 +277,15 @@ ClientSessionFactory::ClientSessionFactory( } Glacier2::SessionPrx -ClientSessionFactory::createGlacier2Session(const string& sessionId, const optional& ctl) +ClientSessionFactory::createGlacier2Session( + const string& sessionId, + const optional& ctl, + const Ice::ConnectionPtr& con) { assert(_servantManager); auto session = createSessionServant(sessionId); - auto proxy = session->_register(_servantManager, nullptr); + auto proxy = session->_register(_servantManager, con); if (ctl) { @@ -308,7 +311,7 @@ ClientSessionFactory::createGlacier2Session(const string& sessionId, const optio // We can't use a non-0 timeout such as the Glacier2 session timeout. As of Ice 3.8, heartbeats may not be sent // at all on a busy connection. Furthermore, as of Ice 3.8, Glacier2 no longer "converts" heartbeats into // keepAlive requests. - _reaper->add(make_shared>(_database->getTraceLevels()->logger, session), 0s); + _reaper->add(make_shared>(_database->getTraceLevels()->logger, session), 0s, con); return Ice::uncheckedCast(proxy); } @@ -327,9 +330,9 @@ ClientSessionFactory::getTraceLevels() const ClientSessionManagerI::ClientSessionManagerI(const shared_ptr& factory) : _factory(factory) {} std::optional -ClientSessionManagerI::create(string user, std::optional ctl, const Ice::Current&) +ClientSessionManagerI::create(string user, std::optional ctl, const Ice::Current& current) { - return _factory->createGlacier2Session(std::move(user), std::move(ctl)); + return _factory->createGlacier2Session(std::move(user), std::move(ctl), current.con); } ClientSSLSessionManagerI::ClientSSLSessionManagerI(const shared_ptr& factory) : _factory(factory) @@ -340,7 +343,7 @@ std::optional ClientSSLSessionManagerI::create( Glacier2::SSLInfo info, std::optional ctl, - const Ice::Current&) + const Ice::Current& current) { string userDN; if (!info.certs.empty()) // TODO: Require userDN? @@ -360,5 +363,5 @@ ClientSSLSessionManagerI::create( } } - return _factory->createGlacier2Session(userDN, ctl); + return _factory->createGlacier2Session(userDN, ctl, current.con); } diff --git a/cpp/src/IceGrid/SessionI.h b/cpp/src/IceGrid/SessionI.h index 059af079736..89df12a83d4 100644 --- a/cpp/src/IceGrid/SessionI.h +++ b/cpp/src/IceGrid/SessionI.h @@ -99,8 +99,10 @@ namespace IceGrid const IceInternal::TimerPtr&, const std::shared_ptr&); - Glacier2::SessionPrx - createGlacier2Session(const std::string&, const std::optional&); + Glacier2::SessionPrx createGlacier2Session( + const std::string& sessionId, + const std::optional& ctl, + const Ice::ConnectionPtr& con); std::shared_ptr createSessionServant(const std::string&);