- Version number changed to 0.1.15-dev
authorVictor Kirhenshtein <victor@netxms.org>
Wed, 23 Feb 2005 20:29:08 +0000 (20:29 +0000)
committerVictor Kirhenshtein <victor@netxms.org>
Wed, 23 Feb 2005 20:29:08 +0000 (20:29 +0000)
- Fixed server crash when client session closed while forced poll still running

include/netxms-version.h
src/server/core/package.cpp
src/server/core/session.cpp
src/server/include/nms_core.h

index 4f60520..6afa495 100644 (file)
@@ -30,8 +30,8 @@
 
 #define NETXMS_VERSION_MAJOR      0
 #define NETXMS_VERSION_MINOR      1
-#define NETXMS_VERSION_BUILD      14
-#define NETXMS_VERSION_STRING     _T("0.1.14")
+#define NETXMS_VERSION_BUILD      15
+#define NETXMS_VERSION_STRING     _T("0.1.15-dev")
 
 
 #endif
index 2e5f072..3fc691d 100644 (file)
@@ -316,7 +316,10 @@ THREAD_RESULT THREAD_CALL DeploymentManager(void *pArg)
 
    // Sanity check
    if (pStartup->dwNumNodes == 0)
+   {
+      pStartup->pSession->DecRefCount();
       return THREAD_OK;
+   }
 
    // Read number of upgrade threads
    dwNumThreads = ConfigReadInt(_T("NumberOfUpgradeThreads"), 10);
@@ -351,6 +354,7 @@ THREAD_RESULT THREAD_CALL DeploymentManager(void *pArg)
    // Send final notification to client
    msg.SetVariable(VID_DEPLOYMENT_STATUS, (WORD)DEPLOYMENT_STATUS_FINISHED);
    pStartup->pSession->SendMessage(&msg);
+   pStartup->pSession->DecRefCount();
 
    // Cleanup
    MutexDestroy(pStartup->mutex);
index c405f29..cc05070 100644 (file)
@@ -152,6 +152,7 @@ THREAD_RESULT THREAD_CALL ClientSession::PollerThreadStarter(void *pArg)
       ((POLLER_START_DATA *)pArg)->pNode,
       ((POLLER_START_DATA *)pArg)->iPollType,
       ((POLLER_START_DATA *)pArg)->dwRqId);
+   ((POLLER_START_DATA *)pArg)->pSession->DecRefCount();
    free(pArg);
    return THREAD_OK;
 }
@@ -187,6 +188,7 @@ ClientSession::ClientSession(SOCKET hSocket, DWORD dwHostAddr)
    m_ppEPPRuleList = NULL;
    m_hCurrFile = -1;
    m_dwFileRqId = 0;
+   m_dwRefCount = 0;
 }
 
 
@@ -397,6 +399,16 @@ void ClientSession::ReadThread(void)
             ((Node *)pObject)->UnlockDCIList(m_dwIndex);
    }
 
+   // Waiting while reference count becomes 0
+   if (m_dwRefCount > 0)
+   {
+      DebugPrintf("Waiting for pending requests...\n");
+      do
+      {
+         ThreadSleep(1);
+      } while(m_dwRefCount > 0);
+   }
+
    DebugPrintf("Session closed\n");
 }
 
@@ -3295,6 +3307,7 @@ void ClientSession::ForcedNodePoll(CSCPMessage *pRequest)
          if (pObject->CheckAccessRights(m_dwUserId, OBJECT_ACCESS_MODIFY))
          {
             ((Node *)pObject)->IncRefCount();
+            m_dwRefCount++;
 
             pData->pNode = (Node *)pObject;
             ThreadCreate(PollerThreadStarter, 0, pData);
@@ -4095,6 +4108,7 @@ void ClientSession::DeployPackage(CSCPMessage *pRequest)
          _tcscpy(pInfo->szPlatform, szPlatform);
          _tcscpy(pInfo->szVersion, szVersion);
 
+         m_dwRefCount++;
          ThreadCreate(DeploymentManager, 0, pInfo);
          msg.SetVariable(VID_RCC, RCC_SUCCESS);
       }
index 274ea27..53e1918 100644 (file)
@@ -269,6 +269,7 @@ private:
    DWORD m_dwUploadCommand;
    DWORD m_dwUploadData;
    TCHAR m_szCurrFileName[MAX_PATH];
+   DWORD m_dwRefCount;
 
    static THREAD_RESULT THREAD_CALL ReadThreadStarter(void *);
    static THREAD_RESULT THREAD_CALL WriteThreadStarter(void *);
@@ -353,6 +354,9 @@ public:
    ClientSession(SOCKET hSocket, DWORD dwHostAddr);
    ~ClientSession();
 
+   void IncRefCount(void) { m_dwRefCount++; }
+   void DecRefCount(void) { if (m_dwRefCount > 0) m_dwRefCount--; }
+
    void Run(void);
 
    void SendMessage(CSCPMessage *pMsg) { m_pSendQueue->Put(pMsg->CreateMessage()); }