Unable to record screen for multiple tests running in parallel or sequential

I am using startScreenRecording() and stopScreenRecording() methods to record screen during test executions. My tests run on browserstack. For a single test the screen recording is fine. But when I execute multiple tests, the test execution fails with an exception ,

org.openqa.selenium.WebDriverException: Appium error: An unknown server-side error occurred 
while processing the command. Original error: Unable to stop the background screen recording: 
Condition unmet after 10207 ms. Timing out. (WARNING: The server did not provide any stacktrace
information)

I have placed the methods startScreenRecording() and stopScreenRecording() on the beforeMethod() and afterMethod() annotations.

Could someone help me where I am going wrong here? Or is it an issue?

make sure startRecord starts AFTER driver start and stopRecord BEFORE driver stop.

Thank you for the response, I have done it that way, it is started after the driver is instantiated and stopped after it is quit.

here is a sample log snippet

15:59:31.188 DEBUG AppiumDriverFactory.startAppiumDriver - Started Android Appium driver
15:59:31.190 INFO  AppiumDriverFactory.startRecording - Starting video...
16:00:06.517 DEBUG TestReporter.addInfoToReport - The test logs have been saved in: TestNG- 
 test=Gradle test-1.log
16:00:53.355 INFO  TestBase.finishTest - Test failed
16:00:53.363 ERROR TestBase.finishTest - org.openqa.selenium.WebDriverException: Appium 
error: An unknown server-side error occurred while processing the command. Original error: Unable 
to stop the background screen recording: Condition unmet after 10135 ms. Timing out. (WARNING: 
The server did not provide any stacktrace information)

The test starts and ends abruptly with the exception

Are there any other working possible solutions that I may try?

share code somewhere. remove sensitive info.

Thanks. I fixed the issue through a loop by retrying to stop the recording and then start it again.

Hello @Aleksei … the issue seems to be recurring. Could you provide any advise on this?

I start the recording just after driver is instantiated and end it before driver is quit (@AfterMethod)

if (getMobilePlatform() == MobilePlatform.ANDROID) {
  while (retryCount < MAX_RETRIES) {
    try {
      startAndroidVideoRecording();
      break;
    } catch (Exception e) {
      logger.debug("Unable to stop background recording.Stop and retry", e);
      ((CanRecordScreen) AppiumDriverBase.getDriver()).stopRecordingScreen();
    }
    retryCount++;
  }

Need your code. Need to check is your driver thread safe. How you start and so on.