Uploaded image for project: 'ACS'
  1. ACS
  2. ACS-17

maciSimpleClient can't be re-initialized after calling destroy

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • Medium
    • None

    Description

      The maciSimpleClient class has a couple of restrictions:

      • You can't have more than one instance created at the same time in your process
      • You can't re-initialize an instance that has been destroyed in the past

      For instance this triggers an error:

      maci::SimpleClient *c1 = new maci::SimpleClient();
      maci::SimpleClient *c2 = new maci::SimpleClient();
      delete c1;
      delete c2;
      

      terminate called after throwing an instance of 'ACSErrTypeCommon::CouldntCreateObjectExImpl'
      Aborted (core dumped)
      

      But this works:

      maci::SimpleClient *c1 = new maci::SimpleClient();
      delete c1;
      maci::SimpleClient *c2 = new maci::SimpleClient();
      delete c2;
      

      Destroying CORBA...
      Client destroyed.
      Destroying CORBA...
      Client destroyed.
      

      We will ignore this issue for the time-being, but to explain why it happens, we can go and take a look into ICT-730. For the ones without access to ICT tickets, the short story is that a safe-guard was added to avoid components (or containers) making use of a maciSimpleClient instance, but this also prevented multiple maciSimpleClient instances in one process regardless of it being a container or not.

      In any case, we are interested in being able to re-init a maciSimpleClient, allowing it to be used for instance in CppUnit setUp/tearDown methods. These examples don't work at the moment:

      //SetUp
      if ( this->client_->init(0, args) != 0) {
          this->client_->login();
          this->lamp_ = this->client_->getComponent<acsexmplLamp::Lamp>(args[1], 0, true);
      }
       
      //TearDown
      this->client_->releaseComponent(args[1]);
      this->client_->logout();
      

      This case fails, because the client is logged out on the first tearDown(), and when trying to call init in the second setUp() it fails, because the client is already initialized, hence the login() and the request of the component is never actually done, leading to a security-check failure in the second tearDown() (Trying to release a component without being logged in).

      This is easily fixed by actually destroying the client in the tearDown() method:

      //TearDown
      this->client_->releaseComponent(args[1]);
      this->client_->logout();
      this->client_->destroy();
      

      However, there's a bug in maciSimpleClient, which generates a core dump:

      CppUnitClientTest::testDummy12021-06-14T15:13:27.812 [GlobalLogger] Logging proxy successfully created.
      2021-06-14T15:13:27.812 Local file logger: Cache saved to '/alma/ACS-2020DEC/acsdata/tmp/acs/ACS_INSTANCE.0/acs_local_log_Manager_62413'.
      2021-06-14T15:13:27.815 [GlobalLogger] ManagerReference generated using localhost address: 'corbaloc::127.0.1.1:3000/Manager'
       : OK
      CppUnitClientTest::testDummy2Caught signal Success, code = 1.  Code interpretation = address not mapped to object.  Date/Time = 2021-06-14T15:13:30.876
      Segmentation fault (core dumped)
      

      This is because the call to destroy() deletes the m_logger variable, but that variable gets only initialized in the constructor. A simple fix to make an instance of maciSimpleClient re-usable is as follows:

      diff --git a/ACS/LGPL/CommonSoftware/maci/ws/src/maciSimpleClient.cpp b/ACS/LGPL/CommonSoftware/maci/ws/src/maciSimpleClient.cpp
      index b17f7908a5..699bc5f85d 100644
      --- a/ACS/LGPL/CommonSoftware/maci/ws/src/maciSimpleClient.cpp
      +++ b/ACS/LGPL/CommonSoftware/maci/ws/src/maciSimpleClient.cpp
      @@ -419,6 +419,10 @@ SimpleClient::init(int argc, char *argv[])
             LoggingProxy::ProcessName(argv[0]);
         LoggingProxy::ThreadName("main");
      +  if (m_logger==0) {
      +       m_logger = new LoggingProxy(0,0,31);
      +  }
      +
         LoggingProxy::init (m_logger);
         ACS_SHORT_LOG((LM_INFO, "Logging proxy successfully created."));
      

      Which checks whether m_logger is initialized or otherwise creates a new instance.

      Attachments

        Activity

          Attach AEDM documents


            People

              Tomas.Staig Tomas Staig
              Tomas.Staig Tomas Staig
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: