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

Awaiting ResponseFuture.headers hangs indefinetly for not implemented services #727

Closed
c-lucera-pvotal opened this issue Aug 8, 2024 · 1 comment

Comments

@c-lucera-pvotal
Copy link
Contributor

Reproduced in grpc: 4.0.0

Per documentations, we should be able to await the headers in any give ResponseFuture call.

However when the call is not implemented, the code hangs indefinitely without completing.

Sample

Using the following code I expect to always have a print at some point

Future<void> testService() async {
    try {
      final client = MyService.instance.client;
      final request = TestRequest(name: "Test");
      final responseFuture = client.sayHello(request);
    
      var header = await responseFuture.headers; //ISSUE IN THIS LINE
      var helloResponse = await responseFuture;
    
      print(helloResponse.message);
    } catch (e) {
      print(e);
    }
}

But in reality what is happening is that the await responseFuture.headers; never completes, hanging this future indefinitely

I created this repository to test this case, it defines a sample proto and it already include the generated pb files inside lib/services, also it includes a Simple application that shows a button to call the service and await for the result.

How to test

  1. Clone this repo
  2. On the root directory run the project, by using flutter run on the console for your device of choice
  3. Tap on the Send request button.

Expected result

A loader is briefly shown, then a error is shown in the text over the button indicating the service is not available.

Actual result

The loader never goes away because the var header = await responseFuture.headers; at line 59 of main.dart never completes.

Details

Running on web I get the following log, showing that something failed asyncronously but it is not rethrown/catched

Error
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 329:10  createErrorWithStack
dart-sdk/lib/_internal/js_dev_runtime/patch/core_patch.dart 265:28            _throw
dart-sdk/lib/core/errors.dart 120:5                                           throwWithStackTrace
dart-sdk/lib/async/zone.dart 1386:11                                          callback
dart-sdk/lib/async/schedule_microtask.dart 40:11                              _microtaskLoop
dart-sdk/lib/async/schedule_microtask.dart 49:5                               _startMicrotaskLoop
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 181:7            <fn>
@c-lucera-pvotal c-lucera-pvotal changed the title awaiting ResponseFuture.headers hangs indefinetly for not implemented services Awaiting ResponseFuture.headers hangs indefinetly for not implemented services Aug 8, 2024
@c-lucera-pvotal
Copy link
Contributor Author

c-lucera-pvotal commented Aug 8, 2024

I suspect the error is originating here:

When terminating the call, everything is canceled/completed but _headers and _trailing

   Future<void> _terminate() async {
    isCancelled = true;
    _timeoutTimer?.cancel();
    // Don't await _responses.close() here. It'll only complete once the done
    // event has been delivered, and it's the caller of this function that is
    // reading from responses as well, so we might end up deadlocked.
    _responses.close();
    _stream?.terminate();
    final futures = <Future>[];
    if (_requestSubscription != null) {
      futures.add(_requestSubscription!.cancel());
    }
    if (_responseSubscription != null) {
      futures.add(_responseSubscription!.cancel());
    }
    await Future.wait(futures);
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant