Browse Source

fix a condition that the cron job will crash the server

Signed-off-by: ryjiang <jiangruiyi@gmail.com>
ryjiang 8 months ago
parent
commit
09c15cb4cc
2 changed files with 11 additions and 2 deletions
  1. 7 0
      server/src/crons/crons.service.ts
  2. 4 2
      server/src/milvus/milvus.service.ts

+ 7 - 0
server/src/crons/crons.service.ts

@@ -68,6 +68,13 @@ export class CronsService {
         return;
       }
 
+      if (!clientCache.has(clientId)) {
+        // if client not connected, stop cron
+        this.schedulerRegistry.deleteCronJob(clientId, data);
+        console.info('Client is not connected, stop cron.', clientId);
+        return;
+      }
+
       try {
         // get client cache data
         const { milvusClient } = clientCache.get(clientId);

+ 4 - 2
server/src/milvus/milvus.service.ts

@@ -162,10 +162,12 @@ export class MilvusService {
       console.info('Deleting client', clientId);
 
       const res = await milvusClient.closeConnection();
-      // clear cache on disconnect
-      clientCache.delete(milvusClient.clientId);
+
       // clear crons
       cronsManager.deleteCronJob(clientId);
+
+      // clear cache on disconnect
+      clientCache.delete(milvusClient.clientId);
       return res;
     }
   }