Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 3.8k
improvement(rooms): redis client closed should fail with indicator#3115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -12,39 +12,70 @@ import { | ||
| import { persistWorkflowOperation } from '@/socket/database/operations' | ||
| import type { AuthenticatedSocket } from '@/socket/middleware/auth' | ||
| import { checkRolePermission } from '@/socket/middleware/permissions' | ||
| import type { IRoomManager } from '@/socket/rooms' | ||
| import type { IRoomManager, UserSession } from '@/socket/rooms' | ||
| import { WorkflowOperationSchema } from '@/socket/validation/schemas' | ||
| const logger = createLogger('OperationsHandlers') | ||
| export function setupOperationsHandlers(socket: AuthenticatedSocket, roomManager: IRoomManager) { | ||
| socket.on('workflow-operation', async (data) => { | ||
| const workflowId = await roomManager.getWorkflowIdForSocket(socket.id) | ||
| const session = await roomManager.getUserSession(socket.id) | ||
| const emitOperationError = ( | ||
| forbidden: { type: string; message: string; operation?: string; target?: string }, | ||
| failed?: { error: string; retryable?: boolean } | ||
| ) => { | ||
| socket.emit('operation-forbidden', forbidden) | ||
| if (failed && data?.operationId) { | ||
| socket.emit('operation-failed', { operationId: data.operationId, ...failed }) | ||
| } | ||
| } | ||
| if (!roomManager.isReady()) { | ||
| emitOperationError( | ||
| { type: 'ROOM_MANAGER_UNAVAILABLE', message: 'Realtime unavailable' }, | ||
| { error: 'Realtime unavailable', retryable: true } | ||
| ) | ||
| return | ||
| } | ||
| let workflowId: string | null = null | ||
| let session: UserSession | null = null | ||
| try { | ||
| workflowId = await roomManager.getWorkflowIdForSocket(socket.id) | ||
| session = await roomManager.getUserSession(socket.id) | ||
| } catch (error) { | ||
| logger.error('Error loading session for workflow operation:', error) | ||
| emitOperationError( | ||
| { type: 'ROOM_MANAGER_UNAVAILABLE', message: 'Realtime unavailable' }, | ||
| { error: 'Realtime unavailable', retryable: true } | ||
| ) | ||
| return | ||
| } | ||
icecrasher321 marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| if (!workflowId || !session) { | ||
| socket.emit('operation-forbidden', { | ||
| type: 'SESSION_ERROR', | ||
| message: 'Session expired, please rejoin workflow', | ||
| }) | ||
| if (data?.operationId) { | ||
| socket.emit('operation-failed', { operationId: data.operationId, error: 'Session expired' }) | ||
| } | ||
| emitOperationError( | ||
| { type: 'SESSION_ERROR', message: 'Session expired, please rejoin workflow' }, | ||
| { error: 'Session expired' } | ||
| ) | ||
| return | ||
| } | ||
| const hasRoom = await roomManager.hasWorkflowRoom(workflowId) | ||
| let hasRoom = false | ||
| try { | ||
| hasRoom = await roomManager.hasWorkflowRoom(workflowId) | ||
| } catch (error) { | ||
| logger.error('Error checking workflow room:', error) | ||
| emitOperationError( | ||
| { type: 'ROOM_MANAGER_UNAVAILABLE', message: 'Realtime unavailable' }, | ||
| { error: 'Realtime unavailable', retryable: true } | ||
| ) | ||
| return | ||
| } | ||
| if (!hasRoom) { | ||
| socket.emit('operation-forbidden', { | ||
| type: 'ROOM_NOT_FOUND', | ||
| message: 'Workflow room not found', | ||
| }) | ||
| if (data?.operationId) { | ||
| socket.emit('operation-failed', { | ||
| operationId: data.operationId, | ||
| error: 'Workflow room not found', | ||
| }) | ||
| } | ||
| emitOperationError( | ||
| { type: 'ROOM_NOT_FOUND', message: 'Workflow room not found' }, | ||
| { error: 'Workflow room not found' } | ||
| ) | ||
| return | ||
| } | ||
| @@ -77,15 +108,15 @@ export function setupOperationsHandlers(socket: AuthenticatedSocket, roomManager | ||
| // Check permissions from cached role for all other operations | ||
| if (!userPresence) { | ||
| logger.warn(`User presence not found for socket ${socket.id}`) | ||
| socket.emit('operation-forbidden', { | ||
| type: 'SESSION_ERROR', | ||
| message: 'User session not found', | ||
| operation, | ||
| target, | ||
| }) | ||
| if (operationId) { | ||
| socket.emit('operation-failed', { operationId, error: 'User session not found' }) | ||
| } | ||
| emitOperationError( | ||
| { | ||
| type: 'SESSION_ERROR', | ||
| message: 'User session not found', | ||
| operation, | ||
| target, | ||
| }, | ||
| { error: 'User session not found' } | ||
| ) | ||
| return | ||
| } | ||
| @@ -97,7 +128,7 @@ export function setupOperationsHandlers(socket: AuthenticatedSocket, roomManager | ||
| logger.warn( | ||
| `User ${session.userId} (role: ${userPresence.role}) forbidden from ${operation} on ${target}` | ||
| ) | ||
| socket.emit('operation-forbidden', { | ||
| emitOperationError({ | ||
| type: 'INSUFFICIENT_PERMISSIONS', | ||
| message: `${permissionCheck.reason} on '${target}'`, | ||
| operation, | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -20,6 +20,15 @@ export function setupWorkflowHandlers(socket: AuthenticatedSocket, roomManager: | ||
| return | ||
| } | ||
| if (!roomManager.isReady()) { | ||
| logger.warn(`Join workflow rejected: Room manager unavailable`) | ||
| socket.emit('join-workflow-error', { | ||
| error: 'Realtime unavailable', | ||
| code: 'ROOM_MANAGER_UNAVAILABLE', | ||
| }) | ||
| return | ||
| } | ||
| logger.info(`Join workflow request from ${userId} (${userName}) for workflow ${workflowId}`) | ||
| // Verify workflow access | ||
| @@ -128,12 +137,20 @@ export function setupWorkflowHandlers(socket: AuthenticatedSocket, roomManager: | ||
| // Undo socket.join and room manager entry if any operation failed | ||
| socket.leave(workflowId) | ||
| await roomManager.removeUserFromRoom(socket.id) | ||
| socket.emit('join-workflow-error', { error: 'Failed to join workflow' }) | ||
| const isReady = roomManager.isReady() | ||
| socket.emit('join-workflow-error', { | ||
| error: isReady ? 'Failed to join workflow' : 'Realtime unavailable', | ||
| code: isReady ? undefined : 'ROOM_MANAGER_UNAVAILABLE', | ||
| }) | ||
icecrasher321 marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| } | ||
| }) | ||
| socket.on('leave-workflow', async () => { | ||
| try { | ||
| if (!roomManager.isReady()) { | ||
| return | ||
| } | ||
| const workflowId = await roomManager.getWorkflowIdForSocket(socket.id) | ||
| const session = await roomManager.getUserSession(socket.id) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.