Jelajahi Sumber

feat: update standalone create_session interval

hujiarui 1 bulan lalu
induk
melakukan
42d9b5d471
1 mengubah file dengan 23 tambahan dan 18 penghapusan
  1. 23 18
      standalone.py

+ 23 - 18
standalone.py

@@ -183,7 +183,11 @@ class StandaloneGCO:
             self.m_instance = instance
 
         self._log("Creating session...")
-        instance.create_session()
+        try:
+            instance.create_session()
+        except Exception:
+            self._cleanup_instance("create_session failed")
+            raise
         self.m_last_login_time = time.time()
         interval = self._get_wait_interval()
         self.m_next_query_time = time.time() + interval
@@ -220,16 +224,6 @@ class StandaloneGCO:
                 self._log(f"Fallback 10-year lock also failed: {lock_err}")
 
     def _dispatch_error_policy(self, action: str, err: Exception) -> None:
-        """
-        Standalone Error Recovery & Dispatch Policy Engine:
-        Executes self-healing actions based on (Action, Exception Domain Type) matrix:
-        - AccountStateError (invalid credentials, banned, incomplete): Permanently disables account, backs off.
-        - 429 on create_session/login: Account-level rate limit. Lock account and back off.
-        - 429 on query: Session alive, egress IP throttled. Do not lock account; rotate proxy.
-        - session expired / 401: Destroy instance and reschedule re-login in 5s.
-        - 403 Forbidden / WAF: IP blocked. Rotate proxy and back off.
-        - Directly maintains logs and timers internally.
-        """
         biz_err = normalize_error(err)
         acc = self.m_cfg.account if (self.m_cfg.account and self.m_cfg.account.username not in ("", "Guest")) else None
 
@@ -268,8 +262,8 @@ class StandaloneGCO:
         # 2. Session expired / 401
         elif isinstance(biz_err, SessionExpiredOrInvalidError):
             if action in ("create_session", "login", "spawn"):
-                self._log(f"❌ [Auth Failed] Session creation failed (401 invalid credentials or challenge). Backing off for 10s...")
-                self.m_last_login_time = time.time() - self.m_cfg.login_interval + 10.0
+                self._log(f"❌ [Auth Failed] Session creation failed (401 invalid credentials or challenge). Backing off for 300s...")
+                self.m_last_login_time = time.time() - self.m_cfg.login_interval + 300.0
                 self._cleanup_instance(f"{action} auth failed")
             else:
                 self._log(f"🔄 [Session Expired] Session died during {action}. Cleaning up instance for re-login in 5s...")
@@ -278,20 +272,31 @@ class StandaloneGCO:
 
         # 3. Permission denied / WAF blocked / 403
         elif isinstance(biz_err, PermissionDeniedError):
-            self._log(f"🛡️ [WAF Blocked] 403 Forbidden detected during {action}. Cleaning instance to rotate proxy (60s cooldown)...")
             self._cleanup_instance(f"{action} waf blocked")
-            self.m_next_query_time = time.time() + 60.0
+            if action in ("create_session", "login", "spawn"):
+                self._log(f"🛡️ [WAF Blocked] 403 Forbidden detected during {action}. Cooling down for 300s...")
+                self.m_last_login_time = time.time() - self.m_cfg.login_interval + 300.0
+            else:
+                self._log(f"🛡️ [WAF Blocked] 403 Forbidden detected during {action}. Cleaning instance to rotate proxy (60s cooldown)...")
+                self.m_next_query_time = time.time() + 60.0
 
         # 4. Network or browser timeout
         elif isinstance(biz_err, NetworkTimeoutError):
-            self._log(f"⏱️ [Timeout] Network/browser timeout during {action}. Retrying in 5s...")
-            self.m_next_query_time = time.time() + 5.0
+            if action in ("create_session", "login", "spawn"):
+                self._log(f"⏱️ [Timeout] Network/browser timeout during {action}. Cooling down for 300s...")
+                self.m_last_login_time = time.time() - self.m_cfg.login_interval + 300.0
+                self._cleanup_instance(f"{action} timeout")
+            else:
+                self._log(f"⏱️ [Timeout] Network/browser timeout during {action}. Retrying in 5s...")
+                self.m_next_query_time = time.time() + 5.0
 
         # 5. Fallback policy
         else:
             self._log(f"⚠️ [{action}] Unexpected error: {biz_err.message} (code={biz_err.code})")
             if action in ("create_session", "worker_loop"):
-                self.m_last_login_time = time.time() - self.m_cfg.login_interval + 5.0
+                self._log(f"🛑 [Session Penalty] {action} failed. Cooling down for 300s (5 min) to prevent traffic burn...")
+                self.m_last_login_time = time.time() - self.m_cfg.login_interval + 300.0
+                self._cleanup_instance(f"{action} unexpected error")
             else:
                 self.m_next_query_time = time.time() + 10.0