chore: sleep to avoid race conditions on intel (#15194)

With the help of build flags this commit we sleep for 0.7 seconds before we make calls to the following status-go functions that crash on intel MacOS.
- `keycard_go.keycardInitFlow`
- `keycard_go.keycardCancelFlow`
- `status_go.initializeApplication`

As per my investigations this crash happens due to a race condition and was not consistently reproducible. Sometimes it would happen and other times it would not.
I know for sure it used to happen in these places and adding a tiny sleep before calling them made sure that the crashes weren't reproducible for me.

I think a 2.1 second delay during onboarding would be acceptable vs the existing condition of the desktop app straight up crashing.
This commit is contained in:
Siddarth Kumar 2024-07-22 20:24:51 +05:30 committed by GitHub
parent 36e3a7cbb5
commit 798ad6d4b3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 20 additions and 2 deletions

View File

@ -97,6 +97,11 @@ QtObject:
proc init*(self: Service) =
if self.doLogging:
debug "init keycard using ", pairingsJson=status_const.KEYCARDPAIRINGDATAFILE
# Do not remove the sleep 700
# This sleep prevents a crash on intel MacOS
# with errors like bad flushGen 12 in prepareForSweep; sweepgen 0
if status_const.IS_MACOS and status_const.IS_INTEL:
sleep 700
let initResp = keycard_go.keycardInitFlow(status_const.KEYCARDPAIRINGDATAFILE)
if self.doLogging:
debug "initialization response: ", initResp
@ -170,8 +175,14 @@ QtObject:
debug "keycardResumeFlow", kcServiceCurrFlow=($self.currentFlow), payload=payload, response=response
proc cancelCurrentFlow*(self: Service) =
# Do not remove the sleep 700
# This sleep prevents a crash on intel MacOS
# with errors like bad flushGen 12 in prepareForSweep; sweepgen 0
if status_const.IS_MACOS and status_const.IS_INTEL:
sleep 700
let response = keycard_go.keycardCancelFlow()
sleep(200)
# sleep 200 is needed for cancel flow
sleep 200
self.currentFlow = KCSFlowType.NoFlow
self.busy = false
if self.doLogging:

View File

@ -5,6 +5,7 @@ import ../app_service/service/accounts/dto/login_request
import ../app_service/service/accounts/dto/create_account_request
import ../app_service/service/accounts/dto/restore_account_request
import ./response_type
import ../constants as status_const
import status_go
@ -263,6 +264,11 @@ proc openedAccounts*(path: string): RpcResponse[JsonNode] =
let mixPanelAppId = getEnv("MIXPANEL_APP_ID")
let mixPanelToken = getEnv("MIXPANEL_TOKEN")
let payload = %* {"dataDir": path, "mixpanelAppId": mixPanelAppId, "mixpanelToken": mixPanelToken}
# Do not remove the sleep 700
# This sleep prevents a crash on intel MacOS
# with errors like bad flushGen 12 in prepareForSweep; sweepgen 0
if status_const.IS_MACOS and status_const.IS_INTEL:
sleep 700
let response = status_go.initializeApplication($payload)
result.result = Json.decode(response, JsonNode)
except RpcException as e:

View File

@ -3,6 +3,7 @@ include env_cli_vars
## Added a constant here cause it's easier to check the app how it behaves
## on other platform if we just change the value here
const IS_MACOS* = defined(macosx)
const IS_INTEL* = defined(amd64)
# For future supporting fingerprints on other platforms
const SUPPORTS_FINGERPRINT* = IS_MACOS
# This is changed during compilation by reading the VERSION file