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
This commit is contained in:
Luke De Feo
2023-04-27 07:28:41 -07:00
committed by Facebook GitHub Bot
parent 7ce19f4359
commit 862592e03d

View File

@@ -63,6 +63,7 @@ export function plugin(client: PluginClient<Events>) {
const metadata = createState<Map<MetadataId, Metadata>>(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<Events>) {
}
});
applyFrameData(processedNodes, frameScan.snapshot);
if (frameScan.frameTime > lastFrameTime) {
applyFrameData(processedNodes, frameScan.snapshot);
lastFrameTime = frameScan.frameTime;
}
applyFrameworkEvents(frameScan);
return true;