Skip to content

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

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

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);
  }

tsavo-at-pieces added a commit to open-runtime/grpc-dart that referenced this issue Jan 3, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 471a8b3
Author: Tsavo Knott <tsavo@pieces.app>
Date:   Fri Jan 3 13:02:16 2025 -0500

    Clean Up CI

commit 1632820
Author: Tsavo Knott <tsavo@pieces.app>
Date:   Fri Jan 3 13:00:20 2025 -0500

    True Upstream Master

commit 1dddfe0
Merge: 774bf81 c9d6286
Author: Tsavo Knott <102485237+tsavo-at-pieces@users.noreply.github.com>
Date:   Fri Jan 3 12:32:24 2025 -0500

    Merge pull request #2 from open-runtime/update-from-upstream

    Update from Upstream Master

commit c9d6286
Merge: 774bf81 9a9c017
Author: Tsavo Knott <tsavo@pieces.app>
Date:   Fri Jan 3 12:31:33 2025 -0500

    Merge branch 'upstream-master' into update-from-upstream

commit 774bf81
Merge: 4a043fa 00eabed
Author: Tsavo Knott <102485237+tsavo-at-pieces@users.noreply.github.com>
Date:   Fri Jan 3 12:13:44 2025 -0500

    Merge pull request #1 from open-runtime/aot_monorepo_compat

    Merging AOT Monorepo Compat into our Main Branch

commit 9a9c017
Author: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Date:   Tue Dec 17 09:58:22 2024 +0100

    Bump vm_service from 14.3.1 to 15.0.0 (grpc#751)

    Bumps [vm_service](https://github.com/dart-lang/sdk/tree/main/pkg) from 14.3.1 to 15.0.0.
    - [Changelog](https://github.com/dart-lang/sdk/blob/main/CHANGELOG.md)
    - [Commits](https://github.com/dart-lang/sdk/commits/HEAD/pkg)

    ---
    updated-dependencies:
    - dependency-name: vm_service
      dependency-type: direct:production
      update-type: version-update:semver-major
    ...

    Signed-off-by: dependabot[bot] <support@github.com>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    Co-authored-by: Moritz <mosum@google.com>

commit 3e94fec
Author: Moritz <mosum@google.com>
Date:   Tue Dec 17 09:53:02 2024 +0100

    Update health.yaml (grpc#753)

    * Update health.yaml

    * Upgrade example

    * Fixes

    * try different syntax

    * without endings

    * test new wf

    * new version

    * Works, use main now

    * Add changelog

commit 6676c20
Author: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Date:   Mon Dec 16 13:37:35 2024 +0000

    Bump dart-lang/setup-dart from 1.6.5 to 1.7.0 (grpc#746)

commit f61b9a3
Author: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Date:   Mon Nov 4 10:45:05 2024 +0000

    Bump actions/checkout from 4.2.0 to 4.2.2 (grpc#744)

commit c063010
Author: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Date:   Tue Oct 1 08:51:16 2024 +0000

    Bump actions/checkout from 4.1.7 to 4.2.0 (grpc#741)

commit 04ba68e
Author: Moritz <mosum@google.com>
Date:   Tue Oct 1 04:46:38 2024 -0400

    Rev package:lints (grpc#740)

    * Rev package:lints

    * Add changelog

    * Run CI on 3.5.0

    * Test with 3.2.0

    * Update .github/workflows/dart.yml

    Co-authored-by: Kevin Moore <kevmoo@users.noreply.github.com>

    * Update .github/workflows/dart.yml

    Co-authored-by: Kevin Moore <kevmoo@users.noreply.github.com>

    ---------

    Co-authored-by: Kevin Moore <kevmoo@users.noreply.github.com>

commit f8bbdce
Author: Kevin Moore <kevmoo@users.noreply.github.com>
Date:   Tue Sep 24 12:07:42 2024 -0700

    ignore unreachable_switch_default in weird switch case (grpc#737)

commit 071ebc5
Author: steffenhaak <haak@aucentiq.com>
Date:   Fri Sep 6 17:13:11 2024 +0200

    fix: keep alive timeout finishes transport instead of connection shutdown (grpc#722)

    * fix: keep alive timeout finishes transport instead of shutting down channel

    * Update keepalive_test.dart

    * Update CHANGELOG.md

    ---------

    Co-authored-by: Moritz <mosum@google.com>

commit 8177633
Author: Moritz <mosum@google.com>
Date:   Fri Sep 6 15:09:54 2024 +0200

    Small fixes (grpc#732)

    * Small fixes

    * Revert changes on file

    * Add changelog

    * Small fixes in keepalive test

    * Add delay

    * Fix symbol visibilty

    * Add try catch for debugging

    * Fail

    * fail

    * Use for loop

commit 38ca626
Author: Lasse R.H. Nielsen <lrn@google.com>
Date:   Mon Sep 2 16:58:43 2024 +0200

    Use `Map.of` instead of `Map.from` in grpc client. (grpc#724)

    * Use `Map.of` instead of `Map.from` in grpc client.

    `Map.of` creates a new map with the same keys, values and *type*
    as the original map, when used without type arguments or context type,
    where `Map.from` creates a `Map<dynamic, dynamic>`.
    (This code failed on an attempt to make `Map.unmodifiable` be more
    strictly typed, like `Map.of` instead of `Map.from`, showing that
    an intermediate map had type `Map<dynamic, dynamic>` unnecessarily).

    Same for using `List.of` instead of `List.from`.

    The new code should be (microscopically) more efficient and type safe,
    and is forwards-compatible with a stronger type on `Map.unmodifiable`.

    (The code can be optimized more. For example
    `List.of(list1)..addAll(list2)` can be just `list1 + list2` or
    `[...list1, ...list2]`, both of which may know the total number
    of elements when doing the initial list allocation.
    This is a minimal change to allow the type changes for `.unmodifiable`
    to get past this very initial blocker in internal tests.)

    * Add changelog and minor version increment.

    And my save removes trailing spaces.

commit 4f6fe9b
Author: c-lucera-pvotal <91328643+c-lucera-pvotal@users.noreply.github.com>
Date:   Wed Aug 28 08:18:15 2024 +0200

    fix: fix headers not completing when call is terminated (grpc#728)

    Fixes grpc#727

commit c18e185
Author: Kevin Moore <kevmoo@users.noreply.github.com>
Date:   Wed Jul 24 14:24:57 2024 -0700

    Fix status badge (grpc#726)

commit b999b64
Author: Galen Warren <galen@cvillewarrens.com>
Date:   Wed Jul 17 08:11:29 2024 -0400

    feat: fix hang that occurs when hot restarting (grpc#718)

commit bf8bbde
Author: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Date:   Mon Jul 1 11:56:47 2024 +0000

    Bump dart-lang/setup-dart from 1.6.4 to 1.6.5 (grpc#720)

commit 4aa4c8c
Author: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Date:   Mon Jul 1 11:52:08 2024 +0000

    Bump actions/checkout from 4.1.6 to 4.1.7 (grpc#719)

commit dee1b2b
Author: Kevin Moore <kevmoo@users.noreply.github.com>
Date:   Wed May 29 17:23:53 2024 -0700

    Update pubspec.yaml

commit 52023d4
Author: Kevin Moore <kevmoo@google.com>
Date:   Tue May 28 14:47:30 2024 -0700

    code fixes

commit ebb7368
Author: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Date:   Wed May 22 06:56:00 2024 +0000

    Bump lints from 3.0.0 to 4.0.0

    Bumps [lints](https://github.com/dart-lang/lints) from 3.0.0 to 4.0.0.
    - [Release notes](https://github.com/dart-lang/lints/releases)
    - [Changelog](https://github.com/dart-lang/lints/blob/main/CHANGELOG.md)
    - [Commits](dart-archive/lints@v3.0.0...v4.0.0)

    ---
    updated-dependencies:
    - dependency-name: lints
      dependency-type: direct:production
      update-type: version-update:semver-major
    ...

    Signed-off-by: dependabot[bot] <support@github.com>

commit 4e65d4b
Author: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Date:   Tue May 21 11:05:38 2024 +0000

    ---
    updated-dependencies:
    - dependency-name: actions/checkout
      dependency-type: direct:production
      update-type: version-update:semver-patch
    ...

    Signed-off-by: dependabot[bot] <support@github.com>

commit 1495453
Author: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Date:   Tue May 21 11:01:10 2024 +0000

    Bump dart-lang/setup-dart from 1.6.2 to 1.6.4

    Bumps [dart-lang/setup-dart](https://github.com/dart-lang/setup-dart) from 1.6.2 to 1.6.4.
    - [Release notes](https://github.com/dart-lang/setup-dart/releases)
    - [Changelog](https://github.com/dart-lang/setup-dart/blob/main/CHANGELOG.md)
    - [Commits](dart-lang/setup-dart@fedb126...f0ead98)

    ---
    updated-dependencies:
    - dependency-name: dart-lang/setup-dart
      dependency-type: direct:production
      update-type: version-update:semver-patch
    ...

    Signed-off-by: dependabot[bot] <support@github.com>

commit 6586b74
Author: Sarah Zakarias <zarah@google.com>
Date:   Tue May 21 12:30:20 2024 +0200

    Add `topics` to `pubspec.yaml` (grpc#712)

commit 9f65399
Author: Moritz <mosum@google.com>
Date:   Fri May 17 14:53:33 2024 +0200

    Move `codec.dart` to former place (grpc#713)

commit 0d02e43
Author: Moritz <mosum@google.com>
Date:   Mon May 6 06:25:06 2024 -0700

    Remove dependency on `package:archive` (grpc#707)

    * Remove dependency on package:archive

    * Test compression on vm only

    * Add licenses

    * Fix analyze issues

    * Fix codec web

    * Fix licenses

    * Add changelog

commit 078fd23
Author: Moritz <mosum@google.com>
Date:   Thu Apr 25 04:45:40 2024 -0700

    Remove generated `StatusCode` (grpc#703)

    * Remove generated `StatusCode`

    * Rev version for breaking change

    * Upgrade min sdk version

    * Fix issues

commit bdbe5f5
Author: Ruben Garcia <RubenGarcia@users.noreply.github.com>
Date:   Mon Apr 22 16:09:18 2024 +0200

    Fix issue 669 (grpc#693)

    * Fix issue 669

    * Update CHANGELOG.md

    * Update CHANGELOG.md

    * Fix dart format issue.
    Fix prefer single quote issue.

    * Update pubspec and changelog to avoid merge check
    publish / validate
    validate packages

    * Add test for GRPC Compression Flag

    * Fix dart analyze issues.

    * Fix latest dart analyze issue (uninizialized variable)

commit bb8b6e5
Author: Moritz <mosum@google.com>
Date:   Fri Apr 19 02:05:59 2024 -0700

    Make protobuf generated imports absolute (grpc#696)

    * Make protobuf generated imports absolute

    * Stop test for now

commit b05fafe
Author: Moritz <mosum@google.com>
Date:   Mon Apr 15 04:43:26 2024 -0700

    Add Health workflow (grpc#699)

    * Add Health workflow

    * Remove license check

commit aece2a4
Author: Abdul Momin <98901875+Curious-x@users.noreply.github.com>
Date:   Mon Apr 15 12:53:00 2024 +0500

    Typo Correction in README.md (grpc#695)

    Corrected typo "RPs" to "RPCs". To avoid confusion.
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