Merge pull request #4212 from balena-io/fix-race

patch: hold request for metadata while waiting for flasher
This commit is contained in:
flowzone-app[bot] 2024-04-26 14:32:11 +00:00 committed by GitHub
commit fa8220d5ba
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 27 additions and 15 deletions

View File

@ -142,7 +142,8 @@ export let requestMetadata: any;
// start the api and spawn the child process // start the api and spawn the child process
spawnChildAndConnect({ spawnChildAndConnect({
withPrivileges: false, withPrivileges: false,
}).then(({ emit, registerHandler }) => { })
.then(({ emit, registerHandler }) => {
// start scanning // start scanning
emit('scan', {}); emit('scan', {});
@ -160,6 +161,9 @@ spawnChildAndConnect({
registerHandler('drives', (data: any) => { registerHandler('drives', (data: any) => {
setDrives(JSON.parse(data)); setDrives(JSON.parse(data));
}); });
})
.catch((error: any) => {
throw new Error(`Failed to start the flasher process. error: ${error}`);
}); });
let popupExists = false; let popupExists = false;

View File

@ -423,6 +423,14 @@ export class SourceSelector extends React.Component<
// this will send an event down the ipcMain asking for metadata // this will send an event down the ipcMain asking for metadata
// we'll get the response through an event // we'll get the response through an event
// FIXME: This is a poor man wait while loading to prevent a potential race condition without completely blocking the interface
// This should be addressed when refactoring the GUI
let retriesLeft = 10;
while (requestMetadata === undefined && retriesLeft > 0) {
await new Promise((resolve) => setTimeout(resolve, 1050)); // api is trying to connect every 1000, this is offset to make sure we fall between retries
retriesLeft--;
}
metadata = await requestMetadata({ selected, SourceType, auth }); metadata = await requestMetadata({ selected, SourceType, auth });
if (!metadata?.hasMBR && this.state.warning === null) { if (!metadata?.hasMBR && this.state.warning === null) {