소스 검색

mutex on disconnect (#413)

SecurityAndStuff 2 년 전
부모
커밋
a0e150791b
1개의 변경된 파일9개의 추가작업 그리고 1개의 파일을 삭제
  1. 9 1
      gramjs/network/MTProtoSender.ts

+ 9 - 1
gramjs/network/MTProtoSender.ts

@@ -277,7 +277,15 @@ export class MTProtoSender {
      * all pending requests, and closes the send and receive loops.
      */
     async disconnect() {
-        await this._disconnect();
+        const release = await this._connectMutex.acquire();
+        try {
+            await this._disconnect();
+        } catch (e: any) {
+            this._log.error(e);
+        }
+        finally {
+            release();
+        }
     }
 
     /**