flutter / flutter

Flutter makes it easy and fast to build beautiful apps for mobile and beyond
https://flutter.dev
BSD 3-Clause "New" or "Revised" License
166.03k stars 27.42k forks source link

java.lang.IllegalStateException: Reply already submitted with simultaneous method calls #29092

Closed crazecoder closed 2 years ago

crazecoder commented 5 years ago

Steps to Reproduce

flutter

Future<Null> avoid() async {
    await _channel.invokeMethod('a', map);
}
Future<Null> bvoid() async {
    await _channel.invokeMethod('b', map);
}

android

@Override
    public void onMethodCall(final MethodCall call, final Result result) {
        if (call.method.equals("a")) {
             result.success("result a");
        } else if(call.method.equals("b")) {
             result.success("result b");
        } else {
             result.notImplemented();
        }
    }

example

avoid();
bvoid();

Logs

 java.lang.IllegalStateException: Reply already submitted
        at io.flutter.view.FlutterNativeView$PlatformMessageHandlerImpl$1.reply(FlutterNativeView.java:197)
        at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler$1.success(MethodChannel.java:204)

An error is reported when two methods are executed at the same time

cedvdb commented 3 years ago

Seems like we were never able to reproduce it #29092 (comment).

If anyone has a reduced reproduction project, we could take a look.

It happens all the time with sms autofill package when hot reloading.

the line that makes the error happen is this one:

  Future<String> get hint async {
    final String version = await _channel.invokeMethod('requestPhoneHint');
    return version;
  }

Basically when hot reloading multiple time, the hint to get user phone number appears multiple times and makes the app crash

stuartmorgan commented 3 years ago

I'm retitling to make it clearer what the original report was, and I'm going to hide a lot of off-topic discussion to make it less confusing.

To be very clear: It is not the case that any instance of Reply already submitted is this issue.

sudo-ulmas commented 3 years ago

Just removing the 2nd result.success() solved the problem

beylmk commented 3 years ago
  • If you find that your logic is correct, and have multiple in-flight method channel requests at the same time, that would be where this issue would be relevant.

@stuartmorgan Can you please explain what you mean by this part? We have checked our logic and feel pretty confident we are not calling a result's response more than once. Are you saying that two of the same requests would cause this error??

stuartmorgan commented 3 years ago

See the original issue description at the top of this page; the reported issue is that having two asynchronous method channel requests in flight at the same time could cause this error. (We haven't verified this yet, but that's the reported issue that's being tracked here.)

blasten commented 3 years ago

@gaaclarke was it intentional to register the handler for the [method channel twice] in (https://github.com/gaaclarke/double_result/blob/master/android/src/main/java/com/example/double_result/DoubleResultPlugin.java)?

cc @GaryQian will be taking a look

GaryQian commented 3 years ago

We are assigning 0 response_id for platform messages that return null/void. This is causing conflict if two messages are passed before the first one has a chance to complete and consume the zero response_id. https://github.com/flutter/engine/blob/master/shell/platform/android/platform_view_android.cc#L230

gaaclarke commented 3 years ago

@gaaclarke was it intentional to register the handler for the [method channel twice] in (https://github.com/gaaclarke/double_result/blob/master/android/src/main/java/com/example/double_result/DoubleResultPlugin.java)?

@blasten I'm not sure. I wrote this a long time ago. Since it was me trying to reproduce a reported bug, it may be possible i was intentionally doing something wrong.

GaryQian commented 3 years ago

Reopening until we confirm this issue has been fixed in the wild.

github-actions[bot] commented 2 years ago

Without additional information, we are unfortunately not sure how to resolve this issue. We are therefore reluctantly going to close this bug for now. If you find this problem please file a new issue with the same description, what happens, logs and the output of 'flutter doctor -v'. All system setups can be slightly different so it's always better to open new issues and reference the related ones. Thanks for your contribution.

github-actions[bot] commented 2 years ago

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.