Skip to content

Commit 2b24810

Browse files
committed
fix more bugbot cleanup comments
1 parent df1a951 commit 2b24810

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

apps/sim/app/api/auth/socket-token/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ export async function POST() {
2020

2121
return NextResponse.json({ token: response.token })
2222
} catch {
23-
return NextResponse.json({ error: 'Authentication required' }, { status: 401 })
23+
return NextResponse.json({ error: 'Failed to generate token' }, { status: 500 })
2424
}
2525
}

apps/sim/app/workspace/providers/socket-provider.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,11 @@ export function SocketProvider({ children, user }: SocketProviderProps) {
208208
cb({ token: freshToken })
209209
} catch (error) {
210210
logger.error('Failed to generate fresh token for connection:', error)
211-
cb({ token: null })
211+
if (error instanceof Error && error.message === 'Authentication required') {
212+
// True auth failure - pass null token, server will reject with "Authentication required"
213+
cb({ token: null })
214+
}
215+
// For server errors, don't call cb - connection will timeout and Socket.IO will retry
212216
}
213217
},
214218
})

apps/sim/socket/handlers/workflow.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ export function setupWorkflowHandlers(socket: AuthenticatedSocket, roomManager:
6060
`Cleaning up socket ${existingUser.socketId} for user ${userId} (${isSameTab ? 'same tab' : 'stale'})`
6161
)
6262
await roomManager.removeUserFromRoom(existingUser.socketId)
63+
roomManager.io.in(existingUser.socketId).socketsLeave(workflowId)
6364
}
6465
}
6566
}
@@ -124,10 +125,9 @@ export function setupWorkflowHandlers(socket: AuthenticatedSocket, roomManager:
124125
)
125126
} catch (error) {
126127
logger.error('Error joining workflow:', error)
127-
socket.emit('error', {
128-
type: 'JOIN_ERROR',
129-
message: 'Failed to join workflow',
130-
})
128+
// Undo socket.join if addUserToRoom or subsequent operations failed
129+
socket.leave(workflowId)
130+
socket.emit('join-workflow-error', { error: 'Failed to join workflow' })
131131
}
132132
})
133133

0 commit comments

Comments
 (0)