From 107b9bcb70e785c2d12515e38b8b296eea7ab8d8 Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Wed, 20 May 2015 10:56:09 -0400 Subject: MAINT-5232: Introduce SUBSYSTEM_CLEANUP() macro and use it for existing LLSomeClass::cleanupClass() calls. This logs the fact of making the call, as well as making it. --- indra/llmessage/tests/llhttpclient_test.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'indra/llmessage') diff --git a/indra/llmessage/tests/llhttpclient_test.cpp b/indra/llmessage/tests/llhttpclient_test.cpp index a32bfa59ce..9356a14f1f 100755 --- a/indra/llmessage/tests/llhttpclient_test.cpp +++ b/indra/llmessage/tests/llhttpclient_test.cpp @@ -42,6 +42,7 @@ #include "lliosocket.h" #include "stringize.h" +#include "llcleanup.h" namespace tut { @@ -66,7 +67,7 @@ namespace tut ~HTTPClientTestData() { delete mClientPump; - LLProxy::cleanupClass(); + SUBSYSTEM_CLEANUP(LLProxy); apr_pool_destroy(mPool); } -- cgit v1.2.3 From 430263746424bd0a7c6647d25d9d1db5eca2e8c0 Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Sat, 23 May 2015 12:41:47 -0400 Subject: MAINT-5232: Make gMessageSystem an LLPounceable. This will permit other subsystems to use gMessageSystem.callWhenReady() to (e.g.) register callbacks as soon as gMessageSystem is fully initialized. --- indra/llmessage/message.cpp | 7 +++++-- indra/llmessage/message.h | 3 ++- indra/llmessage/tests/lltemplatemessagedispatcher_test.cpp | 3 ++- indra/llmessage/tests/lltrustedmessageservice_test.cpp | 3 ++- 4 files changed, 11 insertions(+), 5 deletions(-) (limited to 'indra/llmessage') diff --git a/indra/llmessage/message.cpp b/indra/llmessage/message.cpp index e9ce94ab3b..3c3683f12a 100755 --- a/indra/llmessage/message.cpp +++ b/indra/llmessage/message.cpp @@ -77,6 +77,7 @@ #include "v3math.h" #include "v4math.h" #include "lltransfertargetvfile.h" +#include "llpounceable.h" // Constants //const char* MESSAGE_LOG_FILENAME = "message.log"; @@ -1776,7 +1777,9 @@ std::ostream& operator<<(std::ostream& s, LLMessageSystem &msg) return s; } -LLMessageSystem *gMessageSystem = NULL; +// LLPounceable supports callWhenReady(), to permit clients to queue up (e.g.) +// callback registrations for when gMessageSystem is first assigned +LLPounceable gMessageSystem; // update appropriate ping info void process_complete_ping_check(LLMessageSystem *msgsystem, void** /*user_data*/) @@ -2693,7 +2696,7 @@ void end_messaging_system(bool print_summary) LL_INFOS("Messaging") << str.str().c_str() << LL_ENDL; } - delete gMessageSystem; + delete static_cast(gMessageSystem); gMessageSystem = NULL; } } diff --git a/indra/llmessage/message.h b/indra/llmessage/message.h index 348b09b992..a6fabf2126 100755 --- a/indra/llmessage/message.h +++ b/indra/llmessage/message.h @@ -60,6 +60,7 @@ #include "llmessagesenderinterface.h" #include "llstoredmessage.h" +#include "llpounceable.h" const U32 MESSAGE_MAX_STRINGS_LENGTH = 64; const U32 MESSAGE_NUMBER_OF_HASH_BUCKETS = 8192; @@ -830,7 +831,7 @@ private: // external hook into messaging system -extern LLMessageSystem *gMessageSystem; +extern LLPounceable gMessageSystem; // Must specific overall system version, which is used to determine // if a patch is available in the message template checksum verification. diff --git a/indra/llmessage/tests/lltemplatemessagedispatcher_test.cpp b/indra/llmessage/tests/lltemplatemessagedispatcher_test.cpp index 3b04530c1a..e20f61b73f 100755 --- a/indra/llmessage/tests/lltemplatemessagedispatcher_test.cpp +++ b/indra/llmessage/tests/lltemplatemessagedispatcher_test.cpp @@ -31,11 +31,12 @@ #include "llhost.h" #include "message.h" #include "llsd.h" +#include "llpounceable.h" #include "llhost.cpp" // Needed for copy operator #include "net.cpp" // Needed by LLHost. -LLMessageSystem * gMessageSystem = NULL; +LLPounceable gMessageSystem; // sensor test doubles bool gClearRecvWasCalled = false; diff --git a/indra/llmessage/tests/lltrustedmessageservice_test.cpp b/indra/llmessage/tests/lltrustedmessageservice_test.cpp index 55748ad27e..41f982a7e2 100755 --- a/indra/llmessage/tests/lltrustedmessageservice_test.cpp +++ b/indra/llmessage/tests/lltrustedmessageservice_test.cpp @@ -33,8 +33,9 @@ #include "message.h" #include "llmessageconfig.h" #include "llhttpnode_stub.cpp" +#include "llpounceable.h" -LLMessageSystem* gMessageSystem = NULL; +LLPounceable gMessageSystem; LLMessageConfig::SenderTrust LLMessageConfig::getSenderTrustedness(const std::string& msg_name) -- cgit v1.2.3 From aefdba1230de456784d220982ab8b4dbe3cde17d Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Thu, 25 Jun 2015 17:00:47 -0400 Subject: MAINT-5232: Make LLHTTPClientAdapter not be an LLSingleton. llhttpclientadapter_test.cpp starts its every test by explicitly instantiating a local LLHTTPClientAdapter object. This is an abuse of LLSingleton, and if it had been properly defined (private constructor), it should never have compiled. Looked at the other way, though, every known reference to LLHTTPClientAdapter instantiates a local object. Why did someone think it should be an LLSingleton in the first place? Remove LLSingleton<> as a base class; remove llsingleton.h. This makes llhttpclientadapter_test.cpp work just fine. One might also question what value this class adds. It seems to do very little -- but more significantly, the ONLY references in the source tree are its declaration, definition and test. Nobody actually uses it anywhere. --- indra/llmessage/llhttpclientadapter.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'indra/llmessage') diff --git a/indra/llmessage/llhttpclientadapter.h b/indra/llmessage/llhttpclientadapter.h index 270282c66f..ab0d219155 100755 --- a/indra/llmessage/llhttpclientadapter.h +++ b/indra/llmessage/llhttpclientadapter.h @@ -28,9 +28,8 @@ #define LL_HTTPCLIENTADAPTER_H #include "llhttpclientinterface.h" -#include "llsingleton.h" // LLSingleton<> -class LLHTTPClientAdapter : public LLHTTPClientInterface, public LLSingleton +class LLHTTPClientAdapter : public LLHTTPClientInterface { public: virtual ~LLHTTPClientAdapter(); -- cgit v1.2.3 From 1e803a6bd7a89f60407a1fd2b2697d9e5dd23467 Mon Sep 17 00:00:00 2001 From: Rider Linden Date: Fri, 10 Jun 2016 12:33:39 -0700 Subject: MAINT-6486: Be sure that all the script queue functions hit all objects and scripts in those objects. Convert from responders and callbacks to coroutines. --- indra/llmessage/llassetstorage.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'indra/llmessage') diff --git a/indra/llmessage/llassetstorage.h b/indra/llmessage/llassetstorage.h index 4be677a4b0..0f23754096 100644 --- a/indra/llmessage/llassetstorage.h +++ b/indra/llmessage/llassetstorage.h @@ -181,6 +181,10 @@ protected: // Map of known bad assets typedef std::map toxic_asset_map_t; +// *TODO: these typedefs are passed into the VFS via a legacy C function pointer +// future project would be to convert these to C++ callables (std::function<>) so that +// we can use bind and remove the userData parameter. +// typedef void (*LLGetAssetCallback)(LLVFS *vfs, const LLUUID &asset_id, LLAssetType::EType asset_type, void *user_data, S32 status, LLExtStat ext_status); -- cgit v1.2.3 From d161651cdb2ea8c3e73055cbf4a85510b8da56db Mon Sep 17 00:00:00 2001 From: Rider Linden Date: Thu, 23 Jun 2016 15:03:39 -0700 Subject: MAINT-6521: Allow anonymous connections to bypass the dependency and order tracking. --- indra/llmessage/llcorehttputil.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/llmessage') diff --git a/indra/llmessage/llcorehttputil.cpp b/indra/llmessage/llcorehttputil.cpp index 7742cbc182..9bf38fb336 100644 --- a/indra/llmessage/llcorehttputil.cpp +++ b/indra/llmessage/llcorehttputil.cpp @@ -642,7 +642,7 @@ HttpRequestPumper::HttpRequestPumper(const LLCore::HttpRequest::ptr_t &request) mHttpRequest(request) { mBoundListener = LLEventPumps::instance().obtain("mainloop"). - listen(LLEventPump::inventName(), boost::bind(&HttpRequestPumper::pollRequest, this, _1)); + listen(LLEventPump::ANONYMOUS, boost::bind(&HttpRequestPumper::pollRequest, this, _1)); } HttpRequestPumper::~HttpRequestPumper() -- cgit v1.2.3 From b031b1a6255af0813698bd40586f30f7b0a76f58 Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Wed, 13 Jul 2016 10:43:36 -0400 Subject: MAINT-5011: Derive remaining exception classes from std::exception. In particular: NotImplemented in llhttpnode.cpp RelocateError in llupdateinstaller.cpp LLProtectedDataException, LLCertException and subclasses in llsecapi.h Had to add no-throw destructor overrides to LLCertException and subclasses because otherwise clang complains that the implicitly-generated destructor's exception specification is more lax than the base class's. --- indra/llmessage/llhttpnode.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'indra/llmessage') diff --git a/indra/llmessage/llhttpnode.cpp b/indra/llmessage/llhttpnode.cpp index f235965879..08688ca48b 100644 --- a/indra/llmessage/llhttpnode.cpp +++ b/indra/llmessage/llhttpnode.cpp @@ -31,6 +31,7 @@ #include "llstl.h" #include "llhttpconstants.h" +#include const std::string CONTEXT_HEADERS("headers"); const std::string CONTEXT_PATH("path"); @@ -92,8 +93,9 @@ LLHTTPNode::~LLHTTPNode() namespace { - class NotImplemented + struct NotImplemented: public std::runtime_error { + NotImplemented(): std::runtime_error("LLHTTPNode::NotImplemented") {} }; } -- cgit v1.2.3 From 9c49a6c91dd9b5bbe811fcd91d8992ed6bac33e7 Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Tue, 19 Jul 2016 16:25:25 -0400 Subject: MAINT-5011: Introduce LLException base class for viewer exceptions. This also introduces LLContinueError for exceptions which should interrupt some part of viewer processing (e.g. the current coroutine) but should attempt to let the viewer session proceed. Derive all existing viewer exception classes from LLException rather than from std::runtime_error or std::logic_error. Use BOOST_THROW_EXCEPTION() rather than plain 'throw' to enrich the thrown exception with source file, line number and containing function. --- indra/llmessage/llhttpnode.cpp | 15 ++++++++------- indra/llmessage/tests/commtest.h | 9 +++++---- indra/llmessage/tests/networkio.h | 6 ++++-- 3 files changed, 17 insertions(+), 13 deletions(-) (limited to 'indra/llmessage') diff --git a/indra/llmessage/llhttpnode.cpp b/indra/llmessage/llhttpnode.cpp index 08688ca48b..48ce258ba2 100644 --- a/indra/llmessage/llhttpnode.cpp +++ b/indra/llmessage/llhttpnode.cpp @@ -31,7 +31,8 @@ #include "llstl.h" #include "llhttpconstants.h" -#include +#include "llexception.h" +#include const std::string CONTEXT_HEADERS("headers"); const std::string CONTEXT_PATH("path"); @@ -93,28 +94,28 @@ LLHTTPNode::~LLHTTPNode() namespace { - struct NotImplemented: public std::runtime_error + struct NotImplemented: public LLException { - NotImplemented(): std::runtime_error("LLHTTPNode::NotImplemented") {} + NotImplemented(): LLException("LLHTTPNode::NotImplemented") {} }; } // virtual LLSD LLHTTPNode::simpleGet() const { - throw NotImplemented(); + BOOST_THROW_EXCEPTION(NotImplemented()); } // virtual LLSD LLHTTPNode::simplePut(const LLSD& input) const { - throw NotImplemented(); + BOOST_THROW_EXCEPTION(NotImplemented()); } // virtual LLSD LLHTTPNode::simplePost(const LLSD& input) const { - throw NotImplemented(); + BOOST_THROW_EXCEPTION(NotImplemented()); } @@ -174,7 +175,7 @@ void LLHTTPNode::del(LLHTTPNode::ResponsePtr response, const LLSD& context) cons // virtual LLSD LLHTTPNode::simpleDel(const LLSD&) const { - throw NotImplemented(); + BOOST_THROW_EXCEPTION(NotImplemented()); } // virtual diff --git a/indra/llmessage/tests/commtest.h b/indra/llmessage/tests/commtest.h index 0d149b5258..5dff56b44f 100644 --- a/indra/llmessage/tests/commtest.h +++ b/indra/llmessage/tests/commtest.h @@ -33,15 +33,16 @@ #include "llevents.h" #include "llsd.h" #include "llhost.h" +#include "llexception.h" #include "stringize.h" #include #include -#include #include +#include -struct CommtestError: public std::runtime_error +struct CommtestError: public LLException { - CommtestError(const std::string& what): std::runtime_error(what) {} + CommtestError(const std::string& what): LLException(what) {} }; static bool query_verbose() @@ -68,7 +69,7 @@ static int query_port(const std::string& var) const char* cport = getenv(var.c_str()); if (! cport) { - throw CommtestError(STRINGIZE("missing environment variable" << var)); + BOOST_THROW_EXCEPTION(CommtestError(STRINGIZE("missing environment variable" << var))); } // This will throw, too, if the value of PORT isn't numeric. int port(boost::lexical_cast(cport)); diff --git a/indra/llmessage/tests/networkio.h b/indra/llmessage/tests/networkio.h index 2aff90ca1e..6aaecf9bac 100644 --- a/indra/llmessage/tests/networkio.h +++ b/indra/llmessage/tests/networkio.h @@ -34,6 +34,8 @@ #include "llares.h" #include "llpumpio.h" #include "llhttpclient.h" +#include "llexception.h" +#include /***************************************************************************** * NetworkIO @@ -51,7 +53,7 @@ public: ll_init_apr(); if (! gAPRPoolp) { - throw std::runtime_error("Can't initialize APR"); + BOOST_THROW_EXCEPTION(LLException("Can't initialize APR")); } // Create IO Pump to use for HTTP Requests. @@ -59,7 +61,7 @@ public: LLHTTPClient::setPump(*mServicePump); if (ll_init_ares() == NULL || !gAres->isInitialized()) { - throw std::runtime_error("Can't start DNS resolver"); + BOOST_THROW_EXCEPTION(LLException("Can't start DNS resolver")); } // You can interrupt pump() without waiting the full timeout duration -- cgit v1.2.3 From 3ea324c1c47dc19f6d6dee813afe498b521010e2 Mon Sep 17 00:00:00 2001 From: Glenn Glazer Date: Wed, 20 Jul 2016 11:47:08 -0700 Subject: MAINT=6585: migrate from local python libraries to canonical llbase --- indra/llmessage/tests/test_llsdmessage_peer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/llmessage') diff --git a/indra/llmessage/tests/test_llsdmessage_peer.py b/indra/llmessage/tests/test_llsdmessage_peer.py index e45249b1cb..485a125af0 100755 --- a/indra/llmessage/tests/test_llsdmessage_peer.py +++ b/indra/llmessage/tests/test_llsdmessage_peer.py @@ -37,7 +37,7 @@ from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler mydir = os.path.dirname(__file__) # expected to be .../indra/llmessage/tests/ sys.path.insert(0, os.path.join(mydir, os.pardir, os.pardir, "lib", "python")) from indra.util.fastest_elementtree import parse as xml_parse -from indra.base import llsd +from llbase import llsd from testrunner import freeport, run, debug, VERBOSE import time -- cgit v1.2.3 From 5ab6b73d57818c7aaf9a4bcd0b302854166fd93a Mon Sep 17 00:00:00 2001 From: Glenn Glazer Date: Thu, 21 Jul 2016 14:03:19 -0700 Subject: MAINT-6585: redirect elementtree to llbase version --- indra/llmessage/tests/test_llsdmessage_peer.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'indra/llmessage') diff --git a/indra/llmessage/tests/test_llsdmessage_peer.py b/indra/llmessage/tests/test_llsdmessage_peer.py index 485a125af0..bac18fa374 100755 --- a/indra/llmessage/tests/test_llsdmessage_peer.py +++ b/indra/llmessage/tests/test_llsdmessage_peer.py @@ -34,9 +34,7 @@ import sys from threading import Thread from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler -mydir = os.path.dirname(__file__) # expected to be .../indra/llmessage/tests/ -sys.path.insert(0, os.path.join(mydir, os.pardir, os.pardir, "lib", "python")) -from indra.util.fastest_elementtree import parse as xml_parse +from llbase.fastest_elementtree import parse as xml_parse from llbase import llsd from testrunner import freeport, run, debug, VERBOSE import time -- cgit v1.2.3 From 5e2676994cf1816ff1a39eb69d90662b5087d367 Mon Sep 17 00:00:00 2001 From: Ansariel Hiller Date: Tue, 26 Jul 2016 19:26:28 +0000 Subject: Fix HttpCoroutineAdapter name for clarity --- indra/llmessage/message.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/llmessage') diff --git a/indra/llmessage/message.cpp b/indra/llmessage/message.cpp index cecb2021e7..290b67feb3 100644 --- a/indra/llmessage/message.cpp +++ b/indra/llmessage/message.cpp @@ -4007,7 +4007,7 @@ void LLMessageSystem::sendUntrustedSimulatorMessageCoro(std::string url, std::st { LLCore::HttpRequest::policy_t httpPolicy(LLCore::HttpRequest::DEFAULT_POLICY_ID); LLCoreHttpUtil::HttpCoroutineAdapter::ptr_t - httpAdapter(new LLCoreHttpUtil::HttpCoroutineAdapter("groupMembersRequest", httpPolicy)); + httpAdapter(new LLCoreHttpUtil::HttpCoroutineAdapter("untrustedSimulatorMessage", httpPolicy)); LLCore::HttpRequest::ptr_t httpRequest(new LLCore::HttpRequest); LLCore::HttpOptions::ptr_t httpOpts = LLCore::HttpOptions::ptr_t(new LLCore::HttpOptions); -- cgit v1.2.3 From 5e9d2f57c82a57307a48afea09aa539b9fa80abf Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Wed, 17 Aug 2016 11:36:24 -0400 Subject: MAINT-5011: Use LLTHROW() instead of plain BOOST_THROW_EXCEPTION(). A level of preprocessor indirection lets us later change the implementation if desired. --- indra/llmessage/llhttpnode.cpp | 9 ++++----- indra/llmessage/tests/commtest.h | 3 +-- indra/llmessage/tests/networkio.h | 5 ++--- 3 files changed, 7 insertions(+), 10 deletions(-) (limited to 'indra/llmessage') diff --git a/indra/llmessage/llhttpnode.cpp b/indra/llmessage/llhttpnode.cpp index 48ce258ba2..04b34a296c 100644 --- a/indra/llmessage/llhttpnode.cpp +++ b/indra/llmessage/llhttpnode.cpp @@ -32,7 +32,6 @@ #include "llstl.h" #include "llhttpconstants.h" #include "llexception.h" -#include const std::string CONTEXT_HEADERS("headers"); const std::string CONTEXT_PATH("path"); @@ -103,19 +102,19 @@ namespace { // virtual LLSD LLHTTPNode::simpleGet() const { - BOOST_THROW_EXCEPTION(NotImplemented()); + LLTHROW(NotImplemented()); } // virtual LLSD LLHTTPNode::simplePut(const LLSD& input) const { - BOOST_THROW_EXCEPTION(NotImplemented()); + LLTHROW(NotImplemented()); } // virtual LLSD LLHTTPNode::simplePost(const LLSD& input) const { - BOOST_THROW_EXCEPTION(NotImplemented()); + LLTHROW(NotImplemented()); } @@ -175,7 +174,7 @@ void LLHTTPNode::del(LLHTTPNode::ResponsePtr response, const LLSD& context) cons // virtual LLSD LLHTTPNode::simpleDel(const LLSD&) const { - BOOST_THROW_EXCEPTION(NotImplemented()); + LLTHROW(NotImplemented()); } // virtual diff --git a/indra/llmessage/tests/commtest.h b/indra/llmessage/tests/commtest.h index 5dff56b44f..7c8f27bbd2 100644 --- a/indra/llmessage/tests/commtest.h +++ b/indra/llmessage/tests/commtest.h @@ -38,7 +38,6 @@ #include #include #include -#include struct CommtestError: public LLException { @@ -69,7 +68,7 @@ static int query_port(const std::string& var) const char* cport = getenv(var.c_str()); if (! cport) { - BOOST_THROW_EXCEPTION(CommtestError(STRINGIZE("missing environment variable" << var))); + LLTHROW(CommtestError(STRINGIZE("missing environment variable" << var))); } // This will throw, too, if the value of PORT isn't numeric. int port(boost::lexical_cast(cport)); diff --git a/indra/llmessage/tests/networkio.h b/indra/llmessage/tests/networkio.h index 6aaecf9bac..5eb739393f 100644 --- a/indra/llmessage/tests/networkio.h +++ b/indra/llmessage/tests/networkio.h @@ -35,7 +35,6 @@ #include "llpumpio.h" #include "llhttpclient.h" #include "llexception.h" -#include /***************************************************************************** * NetworkIO @@ -53,7 +52,7 @@ public: ll_init_apr(); if (! gAPRPoolp) { - BOOST_THROW_EXCEPTION(LLException("Can't initialize APR")); + LLTHROW(LLException("Can't initialize APR")); } // Create IO Pump to use for HTTP Requests. @@ -61,7 +60,7 @@ public: LLHTTPClient::setPump(*mServicePump); if (ll_init_ares() == NULL || !gAres->isInitialized()) { - BOOST_THROW_EXCEPTION(LLException("Can't start DNS resolver")); + LLTHROW(LLException("Can't start DNS resolver")); } // You can interrupt pump() without waiting the full timeout duration -- cgit v1.2.3 From 993f54f6e91d78a9c2e1389ad878d6bd46e9be5b Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Wed, 17 Aug 2016 15:40:03 -0400 Subject: MAINT-5011: Try to enrich catch (...) logging throughout viewer. Turns out we have a surprising number of catch (...) clauses in the viewer code base. If all we currently do is LL_ERRS() << "unknown exception" << LL_ENDL; then call CRASH_ON_UNHANDLED_EXCEPTION() instead. If what we do is LL_WARNS() << "unknown exception" << LL_ENDL; then call LOG_UNHANDLED_EXCEPTION() instead. Since many places need LOG_UNHANDLED_EXCEPTION() and nobody catches LLContinueError yet, eliminate LLContinueError& parameter from LOG_UNHANDLED_EXCEPTION(). This permits us to use the same log message as CRASH_ON_UNHANDLED_EXCEPTION(), just with a different severity level. Where a catch (...) clause actually provides contextual information, or makes an error string, add boost::current_exception_diagnostic_information() to try to figure out actual exception class and message. --- indra/llmessage/llavatarnamecache.cpp | 3 ++- indra/llmessage/llcoproceduremanager.cpp | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) (limited to 'indra/llmessage') diff --git a/indra/llmessage/llavatarnamecache.cpp b/indra/llmessage/llavatarnamecache.cpp index 1ca5f58ae2..2dbbc80741 100644 --- a/indra/llmessage/llavatarnamecache.cpp +++ b/indra/llmessage/llavatarnamecache.cpp @@ -43,6 +43,7 @@ #include "llcoros.h" #include "lleventcoro.h" #include "llcorehttputil.h" +#include "llexception.h" #include #include @@ -237,7 +238,7 @@ void LLAvatarNameCache::requestAvatarNameCache_(std::string url, std::vector +#include //========================================================================= // Map of pool sizes for known pools @@ -395,7 +396,8 @@ void LLCoprocedurePool::coprocedureInvokerCoro(LLCoreHttpUtil::HttpCoroutineAdap } catch (...) { - LL_WARNS() << "A non std::exception was thrown from " << coproc->mName << " with id=" << coproc->mId << "." << " in pool \"" << mPoolName << "\"" << LL_ENDL; + LL_WARNS() << "A non std::exception was thrown from " << coproc->mName << " with id=" << coproc->mId << "." << " in pool \"" << mPoolName << "\"\n" + << boost::current_exception_diagnostic_information() << LL_ENDL; } LL_INFOS() << "Finished coprocedure(" << coproc->mName << ")" << " in pool \"" << mPoolName << "\"" << LL_ENDL; -- cgit v1.2.3 From 4d10172d8b2c72fa809e322a3b4ff326b19ff340 Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Thu, 18 Aug 2016 17:33:44 -0400 Subject: MAINT-5011: Catch unhandled exceptions in LLCoros coroutines. Wrap coroutine call in try/catch in top-level coroutine wrapper function LLCoros::toplevel(). Distinguish exception classes derived from LLContinueError (log and continue) from all others (crash with LL_ERRS). Enhance CRASH_ON_UNHANDLED_EXCEPTIONS() and LOG_UNHANDLED_EXCEPTIONS() macros to accept a context string to supplement the log message. This lets us replace many places that called boost::current_exception_diagnostic_information() with LOG_UNHANDLED_EXCEPTIONS() instead, since the explicit calls were mostly to log supplemental information. Provide supplemental information (coroutine name, function parameters) for some of the previous LOG_UNHANDLED_EXCEPTIONS() calls. This information duplicates LL_DEBUGS() information at the top of these functions, but in a typical log file we wouldn't see the LL_DEBUGS() message. Eliminate a few catch (std::exception e) clauses: the information we get from boost::current_exception_diagnostic_information() in a catch (...) clause makes it unnecessary to distinguish. In a few cases, add a final 'throw;' to a catch (...) clause: having logged the local context info, propagate the exception to be caught by higher-level try/catch. In a couple places, couldn't resist reconciling indentation within a particular function: tabs where the rest of the function uses tabs, spaces where the rest of the function uses spaces. In LLLogin::Impl::loginCoro(), eliminate some confusing comments about an array of rewritten URIs that date back to a long-deleted implementation. --- indra/llmessage/llavatarnamecache.cpp | 10 +++++----- indra/llmessage/llcoproceduremanager.cpp | 16 ++++++++-------- 2 files changed, 13 insertions(+), 13 deletions(-) (limited to 'indra/llmessage') diff --git a/indra/llmessage/llavatarnamecache.cpp b/indra/llmessage/llavatarnamecache.cpp index 2dbbc80741..004db546b7 100644 --- a/indra/llmessage/llavatarnamecache.cpp +++ b/indra/llmessage/llavatarnamecache.cpp @@ -44,6 +44,7 @@ #include "lleventcoro.h" #include "llcorehttputil.h" #include "llexception.h" +#include "stringize.h" #include #include @@ -232,13 +233,12 @@ void LLAvatarNameCache::requestAvatarNameCache_(std::string url, std::vector -#include //========================================================================= // Map of pool sizes for known pools @@ -389,15 +390,14 @@ void LLCoprocedurePool::coprocedureInvokerCoro(LLCoreHttpUtil::HttpCoroutineAdap { coproc->mProc(httpAdapter, coproc->mId); } - catch (std::exception &e) - { - LL_WARNS() << "Coprocedure(" << coproc->mName << ") id=" << coproc->mId.asString() << - " threw an exception! Message=\"" << e.what() << "\"" << LL_ENDL; - } catch (...) { - LL_WARNS() << "A non std::exception was thrown from " << coproc->mName << " with id=" << coproc->mId << "." << " in pool \"" << mPoolName << "\"\n" - << boost::current_exception_diagnostic_information() << LL_ENDL; + LOG_UNHANDLED_EXCEPTION(STRINGIZE("Coprocedure('" << coproc->mName + << "', id=" << coproc->mId.asString() + << ") in pool '" << mPoolName << "'")); + // must NOT omit this or we deplete the pool + mActiveCoprocs.erase(itActive); + throw; } LL_INFOS() << "Finished coprocedure(" << coproc->mName << ")" << " in pool \"" << mPoolName << "\"" << LL_ENDL; -- cgit v1.2.3 From d2c3c2f9fe197b1856e9a8ed37aeb56b77e2ff07 Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Thu, 15 Sep 2016 20:18:12 -0400 Subject: MAINT-5232: Normalize LLSingleton subclasses. A shocking number of LLSingleton subclasses had public constructors -- and in several instances, were being explicitly instantiated independently of the LLSingleton machinery. This breaks the new LLSingleton dependency-tracking machinery. It seems only fair that if you say you want an LLSingleton, there should only be ONE INSTANCE! Introduce LLSINGLETON() and LLSINGLETON_EMPTY_CTOR() macros. These handle the friend class LLSingleton; and explicitly declare a private nullary constructor. To try to enforce the LLSINGLETON() convention, introduce a new pure virtual LLSingleton method you_must_use_LLSINGLETON_macro() which is, as you might suspect, defined by the macro. If you declare an LLSingleton subclass without using LLSINGLETON() or LLSINGLETON_EMPTY_CTOR() in the class body, you can't instantiate the subclass for lack of a you_must_use_LLSINGLETON_macro() implementation -- which will hopefully remind the coder. Trawl through ALL LLSingleton subclass definitions, sprinkling in LLSINGLETON() or LLSINGLETON_EMPTY_CTOR() as appropriate. Remove all explicit constructor declarations, public or private, along with relevant 'friend class LLSingleton' declarations. Where destructors are declared, move them into private section as well. Where the constructor was inline but nontrivial, move out of class body. Fix several LLSingleton abuses revealed by making ctors/dtors private: LLGlobalEconomy was both an LLSingleton and the base class for LLRegionEconomy, a non-LLSingleton. (Therefore every LLRegionEconomy instance contained another instance of the LLGlobalEconomy "singleton.") Extract LLBaseEconomy; LLGlobalEconomy is now a trivial subclass of that. LLRegionEconomy, as you might suspect, now derives from LLBaseEconomy. LLToolGrab, an LLSingleton, was also explicitly instantiated by LLToolCompGun's constructor. Extract LLToolGrabBase, explicitly instantiated, with trivial subclass LLToolGrab, the LLSingleton instance. (WARNING: LLToolGrabBase methods have an unnerving tendency to go after LLToolGrab::getInstance(). I DO NOT KNOW what should be the relationship between the instance in LLToolCompGun and the LLToolGrab singleton instance.) LLGridManager declared a variant constructor accepting (const std::string&), with the comment: // initialize with an explicity grid file for testing. As there is no evidence of this being called from anywhere, delete it. LLChicletBar's constructor accepted an optional (const LLSD&). As the LLSD parameter wasn't used, and as there is no evidence of it being passed from anywhere, delete the parameter. LLViewerWindow::shutdownViews() was checking LLNavigationBar:: instanceExists(), then deleting its getInstance() pointer -- leaving a dangling LLSingleton instance pointer, a land mine if any subsequent code should attempt to reference it. Use deleteSingleton() instead. ~LLAppViewer() was calling LLViewerEventRecorder::instance() and then explicitly calling ~LLViewerEventRecorder() on that instance -- leaving the LLSingleton instance pointer pointing to an allocated-but-destroyed instance. Use deleteSingleton() instead. --- indra/llmessage/llcoproceduremanager.h | 6 ++---- indra/llmessage/llexperiencecache.h | 3 +-- indra/llmessage/llproxy.h | 8 +++++--- indra/llmessage/message.h | 4 ++-- indra/llmessage/tests/networkio.h | 3 ++- 5 files changed, 12 insertions(+), 12 deletions(-) (limited to 'indra/llmessage') diff --git a/indra/llmessage/llcoproceduremanager.h b/indra/llmessage/llcoproceduremanager.h index 497367b80c..7d0e83180c 100644 --- a/indra/llmessage/llcoproceduremanager.h +++ b/indra/llmessage/llcoproceduremanager.h @@ -37,7 +37,8 @@ class LLCoprocedurePool; class LLCoprocedureManager : public LLSingleton < LLCoprocedureManager > { - friend class LLSingleton < LLCoprocedureManager > ; + LLSINGLETON(LLCoprocedureManager); + virtual ~LLCoprocedureManager(); public: typedef boost::function SettingQuery_t; @@ -45,9 +46,6 @@ public: typedef boost::function CoProcedure_t; - LLCoprocedureManager(); - virtual ~LLCoprocedureManager(); - /// Places the coprocedure on the queue for processing. /// /// @param name Is used for debugging and should identify this coroutine. diff --git a/indra/llmessage/llexperiencecache.h b/indra/llmessage/llexperiencecache.h index 1002b33f80..8ee7080d38 100644 --- a/indra/llmessage/llexperiencecache.h +++ b/indra/llmessage/llexperiencecache.h @@ -43,7 +43,7 @@ class LLUUID; class LLExperienceCache: public LLSingleton < LLExperienceCache > { - friend class LLSingleton < LLExperienceCache > ; + LLSINGLETON(LLExperienceCache); public: typedef boost::function CapabilityQuery_t; @@ -103,7 +103,6 @@ public: static const int PROPERTY_SUSPENDED; // 1 << 7 private: - LLExperienceCache(); virtual ~LLExperienceCache(); virtual void initSingleton(); diff --git a/indra/llmessage/llproxy.h b/indra/llmessage/llproxy.h index bd23dd39de..688dff7c83 100644 --- a/indra/llmessage/llproxy.h +++ b/indra/llmessage/llproxy.h @@ -218,14 +218,14 @@ enum LLSocks5AuthType */ class LLProxy: public LLSingleton { - LOG_CLASS(LLProxy); -public: /*########################################################################################### METHODS THAT DO NOT LOCK mProxyMutex! ###########################################################################################*/ // Constructor, cannot have parameters due to LLSingleton parent class. Call from main thread only. - LLProxy(); + LLSINGLETON(LLProxy); + LOG_CLASS(LLProxy); +public: // Static check for enabled status for UDP packets. Call from main thread only. static bool isSOCKSProxyEnabled() { return sUDPProxyEnabled; } @@ -239,9 +239,11 @@ public: /*########################################################################################### METHODS THAT LOCK mProxyMutex! DO NOT CALL WHILE mProxyMutex IS LOCKED! ###########################################################################################*/ +private: // Destructor, closes open connections. Do not call directly, use cleanupClass(). ~LLProxy(); +public: // Delete LLProxy singleton. Allows the apr_socket used in the SOCKS 5 control channel to be // destroyed before the call to apr_terminate. Call from main thread only. static void cleanupClass(); diff --git a/indra/llmessage/message.h b/indra/llmessage/message.h index 681de441ce..f6c5d9e228 100644 --- a/indra/llmessage/message.h +++ b/indra/llmessage/message.h @@ -69,10 +69,10 @@ const S32 MESSAGE_MAX_PER_FRAME = 400; class LLMessageStringTable : public LLSingleton { -public: - LLMessageStringTable(); + LLSINGLETON(LLMessageStringTable); ~LLMessageStringTable(); +public: char *getString(const char *str); U32 mUsed; diff --git a/indra/llmessage/tests/networkio.h b/indra/llmessage/tests/networkio.h index 2aff90ca1e..e579b2fb89 100644 --- a/indra/llmessage/tests/networkio.h +++ b/indra/llmessage/tests/networkio.h @@ -43,7 +43,7 @@ // init time. Use the lazy, on-demand initialization we get from LLSingleton. class NetworkIO: public LLSingleton { -public: + LLSINGLETON(NetworkIO); NetworkIO(): mServicePump(NULL), mDone(false) @@ -68,6 +68,7 @@ public: boost::bind(&NetworkIO::done, this, _1)); } +public: bool pump(F32 timeout=10) { // Reset the done flag so we don't pop out prematurely -- cgit v1.2.3 From b98bc258f23c3497a5c0605d1be56d44a058be88 Mon Sep 17 00:00:00 2001 From: andreykproductengine Date: Wed, 12 Oct 2016 20:18:05 +0300 Subject: MAINT-6487 Viewer Objects should not queue too many downloads --- indra/llmessage/llxfer.cpp | 2 +- indra/llmessage/llxfermanager.cpp | 38 ++++++++++++++++++++++++++++++++------ indra/llmessage/llxfermanager.h | 3 ++- 3 files changed, 35 insertions(+), 8 deletions(-) (limited to 'indra/llmessage') diff --git a/indra/llmessage/llxfer.cpp b/indra/llmessage/llxfer.cpp index 4aba5cae72..e0590dfdff 100644 --- a/indra/llmessage/llxfer.cpp +++ b/indra/llmessage/llxfer.cpp @@ -294,7 +294,7 @@ S32 LLXfer::processEOF() } else { - LL_INFOS() << "xfer from " << mRemoteHost << " failed, code " + LL_INFOS() << "xfer from " << mRemoteHost << " failed or aborted, code " << mCallbackResult << ": " << getFileName() << LL_ENDL; } diff --git a/indra/llmessage/llxfermanager.cpp b/indra/llmessage/llxfermanager.cpp index 0ab67b8dda..58d3ee47a1 100644 --- a/indra/llmessage/llxfermanager.cpp +++ b/indra/llmessage/llxfermanager.cpp @@ -401,7 +401,7 @@ U64 LLXferManager::registerXfer(const void *datap, const S32 length) /////////////////////////////////////////////////////////// -void LLXferManager::requestFile(const std::string& local_filename, +U64 LLXferManager::requestFile(const std::string& local_filename, const std::string& remote_filename, ELLPath remote_path, const LLHost& remote_host, @@ -424,10 +424,12 @@ void LLXferManager::requestFile(const std::string& local_filename, { // cout << "requested a xfer already in progress" << endl; - return; + return xferp->mID; } } + U64 xfer_id = 0; + S32 chunk_size = use_big_packets ? LL_XFER_LARGE_PAYLOAD : -1; xferp = (LLXfer *) new LLXfer_File(chunk_size); if (xferp) @@ -438,13 +440,15 @@ void LLXferManager::requestFile(const std::string& local_filename, // around. // Note: according to AaronB, this is here to deal with locks on files that were // in transit during a crash, - if(delete_remote_on_completion && - (remote_filename.substr(remote_filename.length()-4) == ".tmp")) + if( delete_remote_on_completion + && (remote_filename.substr(remote_filename.length()-4) == ".tmp") + && gDirUtilp->fileExists(local_filename)) { LLFile::remove(local_filename); } + xfer_id = getNextID(); ((LLXfer_File *)xferp)->initializeRequest( - getNextID(), + xfer_id, local_filename, remote_filename, remote_path, @@ -457,6 +461,7 @@ void LLXferManager::requestFile(const std::string& local_filename, { LL_ERRS() << "Xfer allocation error" << LL_ENDL; } + return xfer_id; } void LLXferManager::requestFile(const std::string& remote_filename, @@ -616,7 +621,7 @@ void LLXferManager::processReceiveData (LLMessageSystem *mesgsys, void ** /*user if (!xferp) { char U64_BUF[MAX_STRING]; /* Flawfinder : ignore */ - LL_WARNS() << "received xfer data from " << mesgsys->getSender() + LL_INFOS() << "received xfer data from " << mesgsys->getSender() << " for non-existent xfer id: " << U64_to_str(id, U64_BUF, sizeof(U64_BUF)) << LL_ENDL; return; @@ -1103,6 +1108,27 @@ void LLXferManager::retransmitUnackedPackets () } } +/////////////////////////////////////////////////////////// + +void LLXferManager::abortRequestById(U64 xfer_id, S32 result_code) +{ + LLXfer * xferp = findXfer(xfer_id, mReceiveList); + if (xferp) + { + if (xferp->mStatus == e_LL_XFER_IN_PROGRESS) + { + // causes processAbort(); + xferp->abort(result_code); + } + else + { + xferp->mCallbackResult = result_code; + xferp->processEOF(); //should norify requestor + removeXfer(xferp, &mReceiveList); + startPendingDownloads(); + } + } +} /////////////////////////////////////////////////////////// diff --git a/indra/llmessage/llxfermanager.h b/indra/llmessage/llxfermanager.h index b3d110e7a1..d258f0a5ce 100644 --- a/indra/llmessage/llxfermanager.h +++ b/indra/llmessage/llxfermanager.h @@ -140,7 +140,7 @@ class LLXferManager // file requesting routines // .. to file - virtual void requestFile(const std::string& local_filename, + virtual U64 requestFile(const std::string& local_filename, const std::string& remote_filename, ELLPath remote_path, const LLHost& remote_host, @@ -202,6 +202,7 @@ class LLXferManager virtual void retransmitUnackedPackets (); // error handling + void abortRequestById(U64 xfer_id, S32 result_code); virtual void processAbort (LLMessageSystem *mesgsys, void **user_data); }; -- cgit v1.2.3 From 759b4f14d8c9160da928c79dde4bdc95f8fa0021 Mon Sep 17 00:00:00 2001 From: andreykproductengine Date: Thu, 13 Oct 2016 22:49:06 +0300 Subject: MAINT-6828 Removed unnessesary spam in logs --- indra/llmessage/llxfer_file.cpp | 6 +++--- indra/llmessage/llxfermanager.cpp | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'indra/llmessage') diff --git a/indra/llmessage/llxfer_file.cpp b/indra/llmessage/llxfer_file.cpp index 257a13f277..8e2ed890e7 100644 --- a/indra/llmessage/llxfer_file.cpp +++ b/indra/llmessage/llxfer_file.cpp @@ -98,12 +98,12 @@ void LLXfer_File::cleanup () mFp = NULL; } - LLFile::remove(mTempFilename); + LLFile::remove(mTempFilename, ENOENT); if (mDeleteLocalOnCompletion) { LL_DEBUGS() << "Removing file: " << mLocalFilename << LL_ENDL; - LLFile::remove(mLocalFilename); + LLFile::remove(mLocalFilename, ENOENT); } else { @@ -321,7 +321,7 @@ S32 LLXfer_File::processEOF() mCallbackResult = flushval; } - LLFile::remove(mLocalFilename); + LLFile::remove(mLocalFilename, ENOENT); if (!mCallbackResult) { diff --git a/indra/llmessage/llxfermanager.cpp b/indra/llmessage/llxfermanager.cpp index 0ab67b8dda..0232a6e802 100644 --- a/indra/llmessage/llxfermanager.cpp +++ b/indra/llmessage/llxfermanager.cpp @@ -441,7 +441,7 @@ void LLXferManager::requestFile(const std::string& local_filename, if(delete_remote_on_completion && (remote_filename.substr(remote_filename.length()-4) == ".tmp")) { - LLFile::remove(local_filename); + LLFile::remove(local_filename, ENOENT); } ((LLXfer_File *)xferp)->initializeRequest( getNextID(), -- cgit v1.2.3 From 9564600206c0120f2249a48ba54920902c1a11eb Mon Sep 17 00:00:00 2001 From: andreykproductengine Date: Tue, 18 Oct 2016 19:57:19 +0300 Subject: MAINT-6487 Decreasing delay --- indra/llmessage/llxfermanager.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'indra/llmessage') diff --git a/indra/llmessage/llxfermanager.cpp b/indra/llmessage/llxfermanager.cpp index 58d3ee47a1..272dbbc785 100644 --- a/indra/llmessage/llxfermanager.cpp +++ b/indra/llmessage/llxfermanager.cpp @@ -1123,10 +1123,12 @@ void LLXferManager::abortRequestById(U64 xfer_id, S32 result_code) else { xferp->mCallbackResult = result_code; - xferp->processEOF(); //should norify requestor + xferp->processEOF(); //should notify requester removeXfer(xferp, &mReceiveList); - startPendingDownloads(); } + // Since already removed or marked as aborted no need + // to wait for processAbort() to start new download + startPendingDownloads(); } } -- cgit v1.2.3 From e1b0317c04124b4fc72f14dee1c2125cf970b0e0 Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Tue, 6 Dec 2016 19:44:57 -0500 Subject: DRTVWR-418: Remove duplicate testrunner.py --- indra/llmessage/tests/testrunner.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'indra/llmessage') diff --git a/indra/llmessage/tests/testrunner.py b/indra/llmessage/tests/testrunner.py index 5b9beb359b..9a2de71142 100755 --- a/indra/llmessage/tests/testrunner.py +++ b/indra/llmessage/tests/testrunner.py @@ -168,7 +168,10 @@ def run(*args, **kwds): # executable passed as our first arg, # - [no e] child should inherit this process's environment. debug("Running %s...", " ".join(args)) - rc = os.spawnv(os.P_WAIT, args[0], args) + if kwds.get("use_path", False): + rc = os.spawnvp(os.P_WAIT, args[0], args) + else: + rc = os.spawnv(os.P_WAIT, args[0], args) debug("%s returned %s", args[0], rc) return rc -- cgit v1.2.3 From a4ba22fecc8db468377ab14f5652e4176f0488b7 Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Wed, 7 Dec 2016 09:30:49 -0500 Subject: DRTVWR-418: Revamp testrunner to shutdown server Thread at end. Instead of having testrunner.run()'s caller pass a Thread object on which to run the caller's server instance's serve_forever() method, just pass the server instance. testrunner.run() now constructs the Thread. This API change allows run() to also call shutdown() on the server instance when done, and then join() the Thread. The hope is that this will avoid the Python runtime forcing the process termination code to 1 due to forcibly killing the daemon thread still running serve_forever(). While at it, eliminate calls to testrunner.freeport() -- just make the runtime pick a suitable port instead. --- indra/llmessage/tests/test_llsdmessage_peer.py | 16 ++--- indra/llmessage/tests/testrunner.py | 90 ++++++++++++++++++-------- 2 files changed, 69 insertions(+), 37 deletions(-) (limited to 'indra/llmessage') diff --git a/indra/llmessage/tests/test_llsdmessage_peer.py b/indra/llmessage/tests/test_llsdmessage_peer.py index bac18fa374..a0d5d1b354 100755 --- a/indra/llmessage/tests/test_llsdmessage_peer.py +++ b/indra/llmessage/tests/test_llsdmessage_peer.py @@ -36,7 +36,7 @@ from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler from llbase.fastest_elementtree import parse as xml_parse from llbase import llsd -from testrunner import freeport, run, debug, VERBOSE +from testrunner import run, debug, VERBOSE import time _storage=None @@ -155,17 +155,13 @@ class Server(HTTPServer): allow_reuse_address = False if __name__ == "__main__": - # Instantiate a Server(TestHTTPRequestHandler) on the first free port - # in the specified port range. Doing this inline is better than in a - # daemon thread: if it blows up here, we'll get a traceback. If it blew up - # in some other thread, the traceback would get eaten and we'd run the - # subject test program anyway. - httpd, port = freeport(xrange(8000, 8020), - lambda port: Server(('127.0.0.1', port), TestHTTPRequestHandler)) + # Instantiate a Server(TestHTTPRequestHandler) on a port chosen by the + # runtime. + httpd = Server(('127.0.0.1', 0), TestHTTPRequestHandler) # Pass the selected port number to the subject test program via the # environment. We don't want to impose requirements on the test program's # command-line parsing -- and anyway, for C++ integration tests, that's # performed in TUT code rather than our own. - os.environ["PORT"] = str(port) + os.environ["PORT"] = str(httpd.server_port) debug("$PORT = %s", port) - sys.exit(run(server=Thread(name="httpd", target=httpd.serve_forever), *sys.argv[1:])) + sys.exit(run(server_inst=httpd, *sys.argv[1:])) diff --git a/indra/llmessage/tests/testrunner.py b/indra/llmessage/tests/testrunner.py index 9a2de71142..09f0f3c681 100755 --- a/indra/llmessage/tests/testrunner.py +++ b/indra/llmessage/tests/testrunner.py @@ -27,13 +27,12 @@ Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA $/LicenseInfo$ """ -from __future__ import with_statement - import os import sys import re import errno import socket +from threading import Thread VERBOSE = os.environ.get("INTEGRATION_TEST_VERBOSE", "0") # default to quiet # Support usage such as INTEGRATION_TEST_VERBOSE=off -- distressing to user if @@ -47,6 +46,9 @@ if VERBOSE: else: debug = lambda *args: None +class Error(Exception): + pass + def freeport(portlist, expr): """ Find a free server port to use. Specifically, evaluate 'expr' (a @@ -141,39 +143,73 @@ def freeport(portlist, expr): raise def run(*args, **kwds): - """All positional arguments collectively form a command line, executed as - a synchronous child process. - In addition, pass server=new_thread_instance as an explicit keyword (to - differentiate it from an additional command-line argument). - new_thread_instance should be an instantiated but not yet started Thread - subclass instance, e.g.: - run("python", "-c", 'print "Hello, world!"', server=TestHTTPServer(name="httpd")) """ - # If there's no server= keyword arg, don't start a server thread: simply - # run a child process. + Run a specified command as a synchronous child process, optionally + launching a server Thread during the run. + + All positional arguments collectively form a command line. The first + positional argument names the program file to execute. + + Returns the termination code of the child process. + + In addition, you may pass keyword-only arguments: + + use_path=True: allow a simple filename as command and search PATH for that + filename. Otherwise the command must be a full pathname. + + server_inst: an instance of a subclass of SocketServer.BaseServer. + + When you pass server_inst, its serve_forever() method is called on a + separate Thread before the child process is run. It is shutdown() when the + child process terminates. + """ + # server= keyword arg is discontinued try: thread = kwds.pop("server") except KeyError: pass else: - # Start server thread. Note that this and all other comm server - # threads should be daemon threads: we'll let them run "forever," - # confident that the whole process will terminate when the main thread - # terminates, which will be when the child process terminates. + raise Error("Obsolete call to testrunner.run(): pass server_inst=, not server=") + + try: + server_inst = kwds.pop("server_inst") + except KeyError: + # We're not starting a thread, so shutdown() is a no-op. + shutdown = lambda: None + else: + # Make a Thread on which to call server_inst.serve_forever(). + thread = Thread(name="server", target=server_inst.serve_forever) + + # Make this a "daemon" thread. thread.setDaemon(True) thread.start() - # choice of os.spawnv(): - # - [v vs. l] pass a list of args vs. individual arguments, - # - [no p] don't use the PATH because we specifically want to invoke the - # executable passed as our first arg, - # - [no e] child should inherit this process's environment. - debug("Running %s...", " ".join(args)) - if kwds.get("use_path", False): - rc = os.spawnvp(os.P_WAIT, args[0], args) - else: - rc = os.spawnv(os.P_WAIT, args[0], args) - debug("%s returned %s", args[0], rc) - return rc + + # We used to simply call sys.exit() with the daemon thread still + # running -- but in recent versions of Python 2, even when you call + # sys.exit(0), apparently killing the thread causes the Python runtime + # to force the process termination code to 1. So try to play nice. + def shutdown(): + # evidently this call blocks until shutdown is complete + server_inst.shutdown() + # which should make it straightforward to join() + thread.join() + + try: + # choice of os.spawnv(): + # - [v vs. l] pass a list of args vs. individual arguments, + # - [no p] don't use the PATH because we specifically want to invoke the + # executable passed as our first arg, + # - [no e] child should inherit this process's environment. + debug("Running %s...", " ".join(args)) + if kwds.get("use_path", False): + rc = os.spawnvp(os.P_WAIT, args[0], args) + else: + rc = os.spawnv(os.P_WAIT, args[0], args) + debug("%s returned %s", args[0], rc) + return rc + + finally: + shutdown() # **************************************************************************** # test code -- manual at this point, see SWAT-564 -- cgit v1.2.3 From e1482838fe08ab4d0c4aafd22d50f98d0fdee6c1 Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Wed, 7 Dec 2016 09:44:55 -0500 Subject: DRTVWR-418: Fix a couple variable references in debugging output. --- indra/llmessage/tests/test_llsdmessage_peer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/llmessage') diff --git a/indra/llmessage/tests/test_llsdmessage_peer.py b/indra/llmessage/tests/test_llsdmessage_peer.py index a0d5d1b354..8e1204fb20 100755 --- a/indra/llmessage/tests/test_llsdmessage_peer.py +++ b/indra/llmessage/tests/test_llsdmessage_peer.py @@ -163,5 +163,5 @@ if __name__ == "__main__": # command-line parsing -- and anyway, for C++ integration tests, that's # performed in TUT code rather than our own. os.environ["PORT"] = str(httpd.server_port) - debug("$PORT = %s", port) + debug("$PORT = %s", httpd.server_port) sys.exit(run(server_inst=httpd, *sys.argv[1:])) -- cgit v1.2.3 From 2569a1701dd127ae89c4f9e4aaaa6af09fb28d28 Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Wed, 7 Dec 2016 10:20:06 -0500 Subject: DRTVWR-418: Diagnostic prints to identify hangup --- indra/llmessage/tests/testrunner.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'indra/llmessage') diff --git a/indra/llmessage/tests/testrunner.py b/indra/llmessage/tests/testrunner.py index 09f0f3c681..0a53c312fa 100755 --- a/indra/llmessage/tests/testrunner.py +++ b/indra/llmessage/tests/testrunner.py @@ -177,8 +177,14 @@ def run(*args, **kwds): # We're not starting a thread, so shutdown() is a no-op. shutdown = lambda: None else: + # Make a function that reports when serve_forever() returns. + def serve_forever(): + server_inst.serve_forever() + print "%s.serve_forever() returned" % server_inst.__class__.__name__ + sys.stdout.flush() + # Make a Thread on which to call server_inst.serve_forever(). - thread = Thread(name="server", target=server_inst.serve_forever) + thread = Thread(name="server", target=serve_forever) # Make this a "daemon" thread. thread.setDaemon(True) @@ -189,10 +195,16 @@ def run(*args, **kwds): # sys.exit(0), apparently killing the thread causes the Python runtime # to force the process termination code to 1. So try to play nice. def shutdown(): + print "Calling %s.shutdown()" % server_inst.__class__.__name__ + sys.stdout.flush() # evidently this call blocks until shutdown is complete server_inst.shutdown() + print "%s.shutdown() returned" % server_inst.__class__.__name__ + sys.stdout.flush() # which should make it straightforward to join() thread.join() + print "Thread.join() returned" + sys.stdout.flush() try: # choice of os.spawnv(): -- cgit v1.2.3 From 54f95e4d611a192b8a93c23e4c2499096121ae57 Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Wed, 7 Dec 2016 13:25:42 -0500 Subject: DRTVWR-418: Make testrunner.run() avoid extra Thread altogether. --- indra/llmessage/tests/testrunner.py | 94 +++++++++++++++++-------------------- 1 file changed, 42 insertions(+), 52 deletions(-) (limited to 'indra/llmessage') diff --git a/indra/llmessage/tests/testrunner.py b/indra/llmessage/tests/testrunner.py index 0a53c312fa..c25945067e 100755 --- a/indra/llmessage/tests/testrunner.py +++ b/indra/llmessage/tests/testrunner.py @@ -32,7 +32,7 @@ import sys import re import errno import socket -from threading import Thread +import subprocess VERBOSE = os.environ.get("INTEGRATION_TEST_VERBOSE", "0") # default to quiet # Support usage such as INTEGRATION_TEST_VERBOSE=off -- distressing to user if @@ -155,13 +155,13 @@ def run(*args, **kwds): In addition, you may pass keyword-only arguments: use_path=True: allow a simple filename as command and search PATH for that - filename. Otherwise the command must be a full pathname. + filename. (This argument is retained for backwards compatibility but is + now the default behavior.) server_inst: an instance of a subclass of SocketServer.BaseServer. - When you pass server_inst, its serve_forever() method is called on a - separate Thread before the child process is run. It is shutdown() when the - child process terminates. + When you pass server_inst, run() calls its handle_request() method in a + loop until the child process terminates. """ # server= keyword arg is discontinued try: @@ -171,57 +171,47 @@ def run(*args, **kwds): else: raise Error("Obsolete call to testrunner.run(): pass server_inst=, not server=") + debug("Running %s...", " ".join(args)) + try: server_inst = kwds.pop("server_inst") except KeyError: - # We're not starting a thread, so shutdown() is a no-op. - shutdown = lambda: None + # Without server_inst, this is very simple: just run child process. + rc = subprocess.call(args) else: - # Make a function that reports when serve_forever() returns. - def serve_forever(): - server_inst.serve_forever() - print "%s.serve_forever() returned" % server_inst.__class__.__name__ - sys.stdout.flush() - - # Make a Thread on which to call server_inst.serve_forever(). - thread = Thread(name="server", target=serve_forever) - - # Make this a "daemon" thread. - thread.setDaemon(True) - thread.start() - - # We used to simply call sys.exit() with the daemon thread still - # running -- but in recent versions of Python 2, even when you call - # sys.exit(0), apparently killing the thread causes the Python runtime - # to force the process termination code to 1. So try to play nice. - def shutdown(): - print "Calling %s.shutdown()" % server_inst.__class__.__name__ - sys.stdout.flush() - # evidently this call blocks until shutdown is complete - server_inst.shutdown() - print "%s.shutdown() returned" % server_inst.__class__.__name__ - sys.stdout.flush() - # which should make it straightforward to join() - thread.join() - print "Thread.join() returned" - sys.stdout.flush() - - try: - # choice of os.spawnv(): - # - [v vs. l] pass a list of args vs. individual arguments, - # - [no p] don't use the PATH because we specifically want to invoke the - # executable passed as our first arg, - # - [no e] child should inherit this process's environment. - debug("Running %s...", " ".join(args)) - if kwds.get("use_path", False): - rc = os.spawnvp(os.P_WAIT, args[0], args) - else: - rc = os.spawnv(os.P_WAIT, args[0], args) - debug("%s returned %s", args[0], rc) - return rc - - finally: - shutdown() + # We're being asked to run a local server while the child process + # runs. We used to launch a daemon thread calling + # server_inst.serve_forever(), then eventually call sys.exit() with + # the daemon thread still running -- but in recent versions of Python + # 2, even when you call sys.exit(0), apparently killing the thread + # causes the Python runtime to force the process termination code + # nonzero. So now we avoid the extra thread altogether. + + # SocketServer.BaseServer.handle_request() honors a 'timeout' + # attribute, if it's set to something other than None. + # We pick 0.5 seconds because that's the default poll timeout for + # BaseServer.serve_forever(), which is what we used to use. + server_inst.timeout = 0.5 + + child = subprocess.Popen(args) + while child.poll() is None: + # Setting server_inst.timeout is what keeps this handle_request() + # call from blocking "forever." Interestingly, looping over + # handle_request() with a timeout is very like the implementation + # of serve_forever(). We just check a different flag to break out. + # It might be interesting if handle_request() returned an + # indication of whether it in fact handled a request or timed out. + # Oddly, it doesn't. We could discover that by overriding + # handle_timeout(), whose default implementation does nothing -- + # but in fact we really don't care. All that matters is that we + # regularly poll both the child process and the server socket. + server_inst.handle_request() + # We don't bother to capture the rc returned by child.poll() because + # poll() is already defined to capture that in its returncode attr. + rc = child.returncode + + debug("%s returned %s", args[0], rc) + return rc # **************************************************************************** # test code -- manual at this point, see SWAT-564 -- cgit v1.2.3 From 5bb456d80cfbcdfe87526510f3b8297d315afdd8 Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Wed, 7 Dec 2016 14:10:32 -0500 Subject: DRTVWR-418: Apparently (some) Windows hosts still need freeport(). This is the function in indra/llmessage/tests/testrunner.py that iterates through ports in a specified range, looking for an available one. Other platforms understand a specification of port 0 to mean: "You pick one. I'll just use whichever one you picked." --- indra/llmessage/tests/test_llsdmessage_peer.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'indra/llmessage') diff --git a/indra/llmessage/tests/test_llsdmessage_peer.py b/indra/llmessage/tests/test_llsdmessage_peer.py index 8e1204fb20..9cd2959ea1 100755 --- a/indra/llmessage/tests/test_llsdmessage_peer.py +++ b/indra/llmessage/tests/test_llsdmessage_peer.py @@ -31,12 +31,11 @@ $/LicenseInfo$ import os import sys -from threading import Thread from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler from llbase.fastest_elementtree import parse as xml_parse from llbase import llsd -from testrunner import run, debug, VERBOSE +from testrunner import freeport, run, debug, VERBOSE import time _storage=None @@ -155,9 +154,19 @@ class Server(HTTPServer): allow_reuse_address = False if __name__ == "__main__": - # Instantiate a Server(TestHTTPRequestHandler) on a port chosen by the - # runtime. - httpd = Server(('127.0.0.1', 0), TestHTTPRequestHandler) + # function to make a server with specified port + make_server = lambda port: Server(('127.0.0.1', port), TestHTTPRequestHandler) + + if not sys.platform.startswith("win"): + # Instantiate a Server(TestHTTPRequestHandler) on a port chosen by the + # runtime. + httpd = make_server(0) + else: + # "Then there's Windows" + # Instantiate a Server(TestHTTPRequestHandler) on the first free port + # in the specified port range. + httpd, port = freeport(xrange(8000, 8020), make_server) + # Pass the selected port number to the subject test program via the # environment. We don't want to impose requirements on the test program's # command-line parsing -- and anyway, for C++ integration tests, that's -- cgit v1.2.3