-
Notifications
You must be signed in to change notification settings - Fork 701
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
fix: prevent page reload on run trigger to open remote browser #389
base: develop
Are you sure you want to change the base?
Changes from 12 commits
fa11a93
7328ec3
0093340
31840c8
3fe2033
5d636ad
1a55090
f957a7c
058d512
9d3c55b
302ccd1
de2d828
279612d
13d52a4
8c0a832
e077306
8bb2ed3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,13 +68,14 @@ export const MainPage = ({ handleEditRecording, initialContent }: MainPageProps) | |
const readyForRunHandler = useCallback((browserId: string, runId: string) => { | ||
interpretStoredRecording(runId).then(async (interpretation: boolean) => { | ||
if (!aborted) { | ||
if (interpretation) { | ||
notify('success', t('main_page.notifications.interpretation_success', { name: runningRecordingName })); | ||
} else { | ||
notify('success', t('main_page.notifications.interpretation_failed', { name: runningRecordingName })); | ||
// destroy the created browser | ||
await stopRecording(browserId); | ||
} | ||
// if (interpretation) { | ||
// notify('success', t('main_page.notifications.interpretation_success', { name: runningRecordingName })); | ||
// } else { | ||
// notify('success', t('main_page.notifications.interpretation_failed', { name: runningRecordingName })); | ||
// // destroy the created browser | ||
// await stopRecording(browserId); | ||
// } | ||
if (!interpretation) await stopRecording(browserId); | ||
} | ||
setRunningRecordingName(''); | ||
setCurrentInterpretationLog(''); | ||
|
@@ -96,8 +97,19 @@ export const MainPage = ({ handleEditRecording, initialContent }: MainPageProps) | |
rejectUnauthorized: false | ||
}); | ||
setSockets(sockets => [...sockets, socket]); | ||
socket.on('ready-for-run', () => readyForRunHandler(browserId, runId)); | ||
socket.on('debugMessage', debugMessageHandler); | ||
|
||
socket.on('run-completed', (status) => { | ||
if (status === 'success') { | ||
notify('success', t('main_page.notifications.interpretation_success', { name: runningRecordingName })); | ||
} else { | ||
notify('error', t('main_page.notifications.interpretation_failed', { name: runningRecordingName })); | ||
} | ||
setRunningRecordingName(''); | ||
setCurrentInterpretationLog(''); | ||
setRerenderRuns(true); | ||
}); | ||
|
||
setContent('runs'); | ||
if (browserId) { | ||
notify('info', t('main_page.notifications.run_started', { name: runningRecordingName })); | ||
|
@@ -106,10 +118,10 @@ export const MainPage = ({ handleEditRecording, initialContent }: MainPageProps) | |
} | ||
}) | ||
return (socket: Socket, browserId: string, runId: string) => { | ||
socket.off('ready-for-run', () => readyForRunHandler(browserId, runId)); | ||
socket.off('debugMessage', debugMessageHandler); | ||
socket.off('run-completed'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Use identical function references to remove socket listeners. - socket.on('run-completed', (status) => { ... });
- socket.off('run-completed', () => { ... });
+ const handleRunCompleted = (status) => { ... };
+ socket.on('run-completed', handleRunCompleted);
+ socket.off('run-completed', handleRunCompleted);
|
||
} | ||
}, [runningRecordingName, sockets, ids, readyForRunHandler, debugMessageHandler]) | ||
}, [runningRecordingName, sockets, ids, debugMessageHandler]) | ||
|
||
const handleScheduleRecording = (settings: ScheduleSettings) => { | ||
scheduleStoredRecording(runningRecordingId, settings) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codebase verification
Race condition risk confirmed in browser pool management
The current implementation of
BrowserPool
lacks proper synchronization mechanisms. Multiple concurrent requests could potentially pass thehasActiveRobotRun
check before any of them sets the robot run state, as the operations are not atomic. While Node.js's event loop provides some protection, it's not guaranteed to be safe in high-concurrency scenarios.Suggested improvements:
🔗 Analysis chain
Preventing parallel sessions on robot runs.
Blocking new browser sessions when
hasActiveRobotRun
is true is a solid approach. For high-traffic scenarios, consider if multiple requests might pass this check simultaneously (race condition) before the run is registered. If needed, use a lock or queue to serialize these events and avoid edge cases.🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
Length of output: 878
Script:
Length of output: 3944
Script:
Length of output: 14625