Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calling operations on AudioRecorder in quick succession results in a crash #249

Closed
andrewkolos opened this issue Dec 3, 2023 · 6 comments
Labels
bug Something isn't working Windows

Comments

@andrewkolos
Copy link

andrewkolos commented Dec 3, 2023

Hello, thanks for creating and sharing this package. I am considering using it for a Windows Flutter app where the user may start a recording, but may need to restart it within a fraction of a second. This seems to risk crashing the app.

I am happy to provide more details upon request.

Package version: 5.0.1

Environment
Windows 11 Pro
Version 22H2 (OS Build 22621.2715)

output from "flutter doctor -v"
[√] Flutter (Channel stable, 3.13.8, on Microsoft Windows [Version 10.0.22621.2715], locale en-US)
    • Flutter version 3.13.8 on channel stable at C:\Users\Jozz\Documents\GitHub\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 6c4930c4ac (7 weeks ago), 2023-10-18 10:57:55 -0500
    • Engine revision 767d8c75e8
    • Dart version 3.1.4
    • DevTools version 2.25.0

[√] Windows Version (Installed version of Windows is version 10 or higher)

[!] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at C:\Users\Jozz\AppData\Local\Android\sdk
    • Platform android-34, build-tools 34.0.0
    • Java binary at: E:\Programs\New folder\jbr\bin\java
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-b2043.56-10027231)
    ! Some Android licenses not accepted. To resolve this, run: flutter doctor --android-licenses

[√] Chrome - develop for the web
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[√] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.7.0)
    • Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community
    • Visual Studio Community 2022 version 17.7.34003.232
    • Windows 10 SDK version 10.0.22621.0

[√] Android Studio (version 2022.3)
    • Android Studio at E:\Programs\New folder
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-b2043.56-10027231)

[√] VS Code (version 1.84.2)
    • VS Code at C:\Users\Jozz\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.79.20231130

[√] Connected device (3 available)
    • Windows (desktop) • windows • windows-x64    • Microsoft Windows [Version 10.0.22621.2715]
    • Chrome (web)      • chrome  • web-javascript • Google Chrome 119.0.6045.200
    • Edge (web)        • edge    • web-javascript • Microsoft Edge 119.0.2151.93

[√] Network resources
    • All expected network resources are available.

! Doctor found issues in 1 category.

To Reproduce

Repro project: https://github.com/andrewkolos/_repro_start_and_stop_record/tree/main/249_start_and_stop_crash

  1. Instantiate an AudioRecorder.
  2. Start a recording by calling isRecording on the object. await this to wait for the operation to complete.
  3. Immediately call another method on the object, such as start.
  4. App crashes.

Here is a snippet from the aforementioned repro project that causes this crash;

final _rand = Random();
String _getRandomString() => '${_rand.nextInt(1000000000)}.m4a';

// ...

final Stopwatch stopwatch = Stopwatch()..start();
for (int i = 0; i < 10; i++) {
  await Future.delayed(const Duration(milliseconds: 150), () async {
    print('Checking recording status at ${stopwatch.elapsed}');
    if (await recorder.isRecording()) {
      print('Stopping recording $i at ${stopwatch.elapsed}');
      await recorder.stop();
      print('Stopped stopped recording $i at ${stopwatch.elapsed}');
    }
  });
  print('Starting recording ${i + 1} at ${stopwatch.elapsed}');
  await recorder.start(
    const RecordConfig(encoder: AudioEncoder.aacLc),
    path: join(tempDir, _getRandomString()),
  );
  print('Started recording ${i + 1} at ${stopwatch.elapsed}');
}

Here is the output from me running this snippet:

output
Launching lib\main.dart on Windows in debug mode...
Building Windows application...                                    11.3s
√  Built build\windows\runner\Debug\_repro_start_and_stop_record.exe.
Syncing files to device Windows...                                 201ms

Flutter run key commands.
r Hot reload.
R Hot restart.
h List all available interactive commands.
d Detach (terminate "flutter run" but leave application running).
c Clear the screen
q Quit (terminate the application on the device).

A Dart VM Service on Windows is available at: http://127.0.0.1:57659/HrDwwQq1a9o=/
The Flutter DevTools debugger and profiler on Windows is available at: http://127.0.0.1:9102?uri=http://127.0.0.1:57659/HrDwwQq1a9o=/
flutter: Checking recording status at 0:00:00.151305
flutter: Starting recording 1 at 0:00:00.153695
Lost connection to device.

Expected behavior

The code would run without issue, as all AudioRecorder operations are awaited.

@eugenioadapta
Copy link

I have a similar issue, may be connected to it?
Issuing multiple (awaited) operations on AudioRecorder, the app crashes with this stacktrace:

PlatformException(record, Encoder is not started, null, null)
FATAL EXCEPTION: Thread-10
Process: nl.adapta.xx, PID: 3105
java.lang.IllegalStateException: Reply already submitted
E/AndroidRuntime( 3105): at io.flutter.embedding.engine.dart.DartMessenger$Reply.reply(DartMessenger.java:435)
E/AndroidRuntime( 3105): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler$1.success(MethodChannel.java:263)
E/AndroidRuntime( 3105): at com.llfbandit.record.methodcall.RecorderWrapper$stop$1.invoke(RecorderWrapper.kt:97)
E/AndroidRuntime( 3105): at com.llfbandit.record.methodcall.RecorderWrapper$stop$1.invoke(RecorderWrapper.kt:97)
E/AndroidRuntime( 3105): at com.llfbandit.record.record.AudioRecorder.onStop(AudioRecorder.kt:117)
E/AndroidRuntime( 3105): at com.llfbandit.record.record.RecordThread.updateState(RecordThread.kt:154)
E/AndroidRuntime( 3105): at com.llfbandit.record.record.RecordThread.onEncoderStop(RecordThread.kt:60)
E/AndroidRuntime( 3105): at com.llfbandit.record.record.encoder.PassthroughEncoder$EncodeThread.encode(PassthroughEncoder.kt:95)
E/AndroidRuntime( 3105): at com.llfbandit.record.record.encoder.PassthroughEncoder$EncodeThread.run(PassthroughEncoder.kt:56)
I/Process ( 3105): Sending signal. PID: 3105 SIG: 9
Lost connection to device.

@llfbandit
Copy link
Owner

Thanks for the report.
Unfornately, Windows platform does not have methods to ensure the message will be sent from the main thread.
Here's a relevant issue on Flutter about this: flutter/flutter#134346

@eugenioadapta This is not the same issue. Please fill another one for this with a reproducer.

@andrewkolos
Copy link
Author

andrewkolos commented Dec 13, 2023

\Windows platform does not have methods to ensure the message will be sent from the main thread. Here's a relevant issue on Flutter about this: flutter/flutter#134346

Oh, this all makes sense then. I've left a 👍 reaction on the Flutter issue, as they use that as one signal when prioritizing issues. For anyone else encountering this issue, I recommend that you also add a 👍 to flutter/flutter#134346.

@llfbandit llfbandit added bug Something isn't working Windows labels Dec 14, 2023
@NhaPCS
Copy link

NhaPCS commented Dec 16, 2023

same for me

@llfbandit
Copy link
Owner

@andrewkolos I answered too quickly to this issue.
When I tried to reproduce it I got platform thread issue but this issue is not related to it.
A fix has been released in record 5.0.2 aside record_windows 1.0.2 as an attempt.

@bayasdev
Copy link

I have a similar issue, may be connected to it? Issuing multiple (awaited) operations on AudioRecorder, the app crashes with this stacktrace:

PlatformException(record, Encoder is not started, null, null) FATAL EXCEPTION: Thread-10 Process: nl.adapta.xx, PID: 3105 java.lang.IllegalStateException: Reply already submitted E/AndroidRuntime( 3105): at io.flutter.embedding.engine.dart.DartMessenger$Reply.reply(DartMessenger.java:435) E/AndroidRuntime( 3105): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler$1.success(MethodChannel.java:263) E/AndroidRuntime( 3105): at com.llfbandit.record.methodcall.RecorderWrapper$stop$1.invoke(RecorderWrapper.kt:97) E/AndroidRuntime( 3105): at com.llfbandit.record.methodcall.RecorderWrapper$stop$1.invoke(RecorderWrapper.kt:97) E/AndroidRuntime( 3105): at com.llfbandit.record.record.AudioRecorder.onStop(AudioRecorder.kt:117) E/AndroidRuntime( 3105): at com.llfbandit.record.record.RecordThread.updateState(RecordThread.kt:154) E/AndroidRuntime( 3105): at com.llfbandit.record.record.RecordThread.onEncoderStop(RecordThread.kt:60) E/AndroidRuntime( 3105): at com.llfbandit.record.record.encoder.PassthroughEncoder$EncodeThread.encode(PassthroughEncoder.kt:95) E/AndroidRuntime( 3105): at com.llfbandit.record.record.encoder.PassthroughEncoder$EncodeThread.run(PassthroughEncoder.kt:56) I/Process ( 3105): Sending signal. PID: 3105 SIG: 9 Lost connection to device.

I'm getting the same stack trace as yours

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Windows
Projects
None yet
Development

No branches or pull requests

5 participants