From 862592e03db6f84e885c6ef8f9487be482bd0371 Mon Sep 17 00:00:00 2001 From: Luke De Feo Date: Thu, 27 Apr 2023 07:28:41 -0700 Subject: [PATCH] Account for race conditions with stream intercetor Summary: Given that stream interceptor is async the folling race conditino could occur. Frame at time t=0 comes in, we yeild to the event loop while fetching metadata, fetch takes 5 ticks Frame at time t=1 comes in, we yeild to the event loop but fetch takes 1 tick At time t=2 the second frame is augmented and display At time t=5 the first fetch returns and we display and older frame This is a simple check to avoid this. Reviewed By: aigoncharov Differential Revision: D45314013 fbshipit-source-id: 054e7e6beb52dfbfd94bc9f8ee3d0a758a669f66 --- desktop/plugins/public/ui-debugger/index.tsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/desktop/plugins/public/ui-debugger/index.tsx b/desktop/plugins/public/ui-debugger/index.tsx index 45acc3141..64791bfa9 100644 --- a/desktop/plugins/public/ui-debugger/index.tsx +++ b/desktop/plugins/public/ui-debugger/index.tsx @@ -63,6 +63,7 @@ export function plugin(client: PluginClient) { const metadata = createState>(new Map()); const streamInterceptor = getStreamInterceptor(); + let lastFrameTime = 0; const device = client.device.os; client.onMessage('init', (event) => { @@ -249,7 +250,10 @@ export function plugin(client: PluginClient) { } }); - applyFrameData(processedNodes, frameScan.snapshot); + if (frameScan.frameTime > lastFrameTime) { + applyFrameData(processedNodes, frameScan.snapshot); + lastFrameTime = frameScan.frameTime; + } applyFrameworkEvents(frameScan); return true;