AnsweredAssumed Answered

AF SDK - Deadlock During Communication with AF Database (Delete AF Elements, Get Configuration from an AF Element/Childs/Attributes)

Question asked by fs@ctsGmbH on Jan 17, 2019
Latest reply on Jan 21, 2019 by fs@ctsGmbH

Hello there,

 

I have some troubles with the AF SDK.

 

I perform some actions on an AF Server and Database.
The Actions are evertime the same calls and dont lock something.

I am using a TCP Server for incomming calls and the read the data and send back the result.

 

After some time or days my methode starts to beginn with work, but never ends.
I had a look in the Log file but no errors here, and the Application is still running only stucking in the Methode.

 

Here my Connection handling with af servers.

Some Infos here:

I connect to a AF Server and never call Disconnect => only Connect again as u can see above

 

public bool ConnectToAF(JObject jDataObject, ref PISystem CurrentPISystem)
      {
         bool bConnected = false;
         string sAFServer = IsNullorEmpty((string)jDataObject["afserver"]);


         try
         {
            if ((string)jDataObject["afserver"] != null)
            {
               PISystem localPISystem = null;


               PISystem pISystemCache = (PISystem)FindinDictionary(ref _DicKnownPISystems, sAFServer);


               if (pISystemCache != null)
               {
                  localPISystem = pISystemCache;
               }
               else
               {
                  localPISystem = _piSystems[(string)jDataObject["afserver"]];
                  localPISystem.ConnectionInfo.TimeOut = new TimeSpan(0, 1, 0);
               }


               if (localPISystem != null)
               {                                    
                  localPISystem.Connect();


                  if (localPISystem.ConnectionInfo.IsConnected)
                  {                     


                     _logger.Info("Connection to PI AF server successfully established: " + localPISystem.Name);


                     AddValueToDictionary(ref _DicKnownPISystems, (string)jDataObject["afserver"], localPISystem);
                     CurrentPISystem = localPISystem;
                     bConnected = true;
                  }
                  else
                  {
                     _logger.Debug("Connection to PI AF server is already established: " + localPISystem.Name);
                     CurrentPISystem = localPISystem;
                     bConnected = true;
                  }
               }
               else
               {
                  throw new Exception("PI AF server not reachable!");
               }
            }
            else
            {
            }
         }
         catch (Exception ex)
         {
            _logger.Error("No connection to the PI AF server: " + sAFServer);
            _logger.Error(ex.Message);
         }


         return bConnected;
      }



























 

I am doing something wronge with the Connection handling or do someone know some issues?

 

--------------------------------    Update ----------------------------------------------------

 

i analysed the dump and figured out that i have a deadlock.

I am using an async programming for calling a class, which is handling the communication between PISDK and AFSDK.

 

 

CLR thread 0x4 holds the lock on SyncBlock 000000ba3283d9c8 OBJ:000000ba1ae853e8[OSIsoft.AF.Support.AFUpdateStamp]
...and is waiting for the lock on SyncBlock 000000ba33a33a78 OBJ:
000000ba1a5e6f30[OSIsoft.AF.Support.AFDatabaseStateItem]
CLR thread 0x23 holds the lock on SyncBlock 000000ba33a33a78 OBJ:
000000ba1a5e6f30[OSIsoft.AF.Support.AFDatabaseStateItem]
...and is waiting for the lock on SyncBlock 000000ba3283d9c8 OBJ:
000000ba1ae853e8[OSIsoft.AF.Support.AFUpdateStamp]
CLR Thread 0x4 is waiting at OSIsoft.AF.Support.AFDatabaseStateItem.AddCheckedOutItem(OSIsoft.AF.AFObject)(+0x10 IL,+0x45 Native)
CLR Thread 0x23 is waiting at OSIsoft.AF.AFObject.UpdateHeaderIfNewer(OSIsoft.AF.Service.IdcObjectData, OSIsoft.AF.Service.IdcObjectHeader)(+0x1e IL,+0x6f Native)

 

can anyone help me with this?

 

 

Thanks all,

Flo

Outcomes