dragxd commited on
Commit
1f18aa5
·
1 Parent(s): f6f33ae

Prevent restoring invalidated session files - mark and skip AUTH_KEY_DUPLICATED sessions

Browse files
Files changed (2) hide show
  1. utils/clients.py +5 -1
  2. utils/extra.py +8 -1
utils/clients.py CHANGED
@@ -92,13 +92,17 @@ async def initialize_clients():
92
  multi_clients[client_id] = client
93
  work_loads[client_id] = 0
94
  except AuthKeyDuplicated as e:
95
- # Delete the invalidated session file first
96
  session_file = None
97
  try:
98
  session_file = session_cache_path / f"{client_name}.session"
99
  if session_file.exists():
100
  session_file.unlink()
101
  logger.info(f"Deleted invalidated session file: {session_file}")
 
 
 
 
102
  except Exception as cleanup_error:
103
  logger.error(f"Failed to delete session file: {cleanup_error}")
104
 
 
92
  multi_clients[client_id] = client
93
  work_loads[client_id] = 0
94
  except AuthKeyDuplicated as e:
95
+ # Delete the invalidated session file and mark it as invalidated
96
  session_file = None
97
  try:
98
  session_file = session_cache_path / f"{client_name}.session"
99
  if session_file.exists():
100
  session_file.unlink()
101
  logger.info(f"Deleted invalidated session file: {session_file}")
102
+ # Create a marker file so we don't restore this session on next restart
103
+ invalidated_marker = session_cache_path / f"{client_name}.session.invalidated"
104
+ invalidated_marker.touch()
105
+ logger.info(f"Marked session file as invalidated: {invalidated_marker}")
106
  except Exception as cleanup_error:
107
  logger.error(f"Failed to delete session file: {cleanup_error}")
108
 
utils/extra.py CHANGED
@@ -63,10 +63,17 @@ def reset_cache_dir():
63
  cache_dir = Path("./cache")
64
  downloads_dir = Path("./downloads")
65
 
66
- # Save session files before deleting cache
67
  session_files = {}
68
  if cache_dir.exists():
69
  for session_file in cache_dir.glob("*.session"):
 
 
 
 
 
 
 
70
  session_files[session_file.name] = session_file.read_bytes()
71
  logger.info(f"Preserving session file: {session_file.name}")
72
 
 
63
  cache_dir = Path("./cache")
64
  downloads_dir = Path("./downloads")
65
 
66
+ # Save session files before deleting cache (but skip invalidated ones)
67
  session_files = {}
68
  if cache_dir.exists():
69
  for session_file in cache_dir.glob("*.session"):
70
+ # Check if this session file was marked as invalidated
71
+ invalidated_marker = cache_dir / f"{session_file.name}.invalidated"
72
+ if invalidated_marker.exists():
73
+ logger.warning(f"Skipping invalidated session file: {session_file.name} (was marked as AUTH_KEY_DUPLICATED)")
74
+ # Delete the marker file so it can be retried on next restart
75
+ invalidated_marker.unlink(missing_ok=True)
76
+ continue
77
  session_files[session_file.name] = session_file.read_bytes()
78
  logger.info(f"Preserving session file: {session_file.name}")
79