|
15 | 15 | from models_library.api_schemas_webserver.socketio import SocketIORoomStr |
16 | 16 | from models_library.projects import ProjectID, ProjectTemplateType |
17 | 17 | from models_library.projects import ProjectType as ProjectTypeAPI |
| 18 | +from servicelib.logging_errors import create_troubleshootting_log_kwargs |
18 | 19 | from servicelib.redis import ( |
19 | 20 | PROJECT_DB_UPDATE_REDIS_LOCK_KEY, |
20 | 21 | exclusive, |
@@ -156,16 +157,40 @@ async def remove_project_documents_as_admin(app: web.Application) -> None: |
156 | 157 | project_uuid, |
157 | 158 | ) |
158 | 159 | else: |
| 160 | + # Create a synthetic exception for this unexpected state |
| 161 | + unexpected_state_error = RuntimeError( |
| 162 | + f"Project {project_uuid} has {len(room_sessions)} connected users but is not in Redis Resources table" |
| 163 | + ) |
159 | 164 | _logger.error( |
160 | | - "Project %s has %d connected users in the socket io room (This is not expected, as project resource is not in the Redis Resources table), keeping document just in case", |
161 | | - project_uuid, |
162 | | - len(room_sessions), |
| 165 | + **create_troubleshootting_log_kwargs( |
| 166 | + user_error_msg=f"Project {project_uuid} has {len(room_sessions)} connected users in the socket io room (This is not expected, as project resource is not in the Redis Resources table), keeping document just in case", |
| 167 | + error=unexpected_state_error, |
| 168 | + error_context={ |
| 169 | + "project_uuid": str(project_uuid), |
| 170 | + "project_room": project_room, |
| 171 | + "key_str": key_str, |
| 172 | + "connected_users_count": len(room_sessions), |
| 173 | + "room_sessions": room_sessions[ |
| 174 | + :5 |
| 175 | + ], # Limit to first 5 sessions for debugging |
| 176 | + }, |
| 177 | + tip="This indicates a potential race condition or inconsistency between the Redis Resources table and socketio room state. Check if the project was recently closed but users are still connected, or if there's a synchronization issue between services.", |
| 178 | + ) |
163 | 179 | ) |
| 180 | + continue |
164 | 181 |
|
165 | | - except (KeyError, AttributeError, ValueError): |
| 182 | + except (KeyError, AttributeError, ValueError) as exc: |
166 | 183 | _logger.exception( |
167 | | - "Failed to check room participants for project %s", |
168 | | - project_uuid, |
| 184 | + **create_troubleshootting_log_kwargs( |
| 185 | + user_error_msg=f"Failed to check room participants for project {project_uuid}", |
| 186 | + error=exc, |
| 187 | + error_context={ |
| 188 | + "project_uuid": str(project_uuid), |
| 189 | + "project_room": project_room, |
| 190 | + "key_str": key_str, |
| 191 | + }, |
| 192 | + tip="Check if socketio server is properly initialized and the room exists. This could indicate a socketio manager issue or invalid room format.", |
| 193 | + ) |
169 | 194 | ) |
170 | 195 | continue |
171 | 196 |
|
|
0 commit comments