Skip to content

DdsExtension.onEventWithHistory implementation seems incorrect #60672

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

Open
mraleph opened this issue May 5, 2025 · 1 comment
Open

DdsExtension.onEventWithHistory implementation seems incorrect #60672

mraleph opened this issue May 5, 2025 · 1 comment
Assignees
Labels
area-pkg Used for miscellaneous pkg/ packages not associated with specific area- teams. pkg-dds For issues related to the Dart Development Service type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@mraleph
Copy link
Member

mraleph commented May 5, 2025

The implementation does the following intermixing of async and sync code:

      final history = (await getStreamHistory(stream)).history;
      Event? firstStreamEvent;
      unawaited(streamEvents.peek.then((e) {
        firstStreamEvent = e;
      }));
      for (final event in history) {
        if (firstStreamEvent != null &&
            event.timestamp! > firstStreamEvent!.timestamp!) {
          break;
        }

Future.then is never executed synchronously (at least not for builtin implementation of Future) - which means firstStreamEvent is always null and the code does not do what it is expected to do.

Also the way code is written it leaves any errors thrown by peek unhandled instead of properly forwarding them into Stream returned by onEventWithHistory.

This was revealed when I tried adding code to properly close event streams when underlying VmService connection goes away. I have now undone this change because onEventWithHistory needs to be fixed first.

diff --git a/pkg/vm_service/lib/src/vm_service.dart b/pkg/vm_service/lib/src/vm_service.dart
index e14557b3bf3..a32c9f4915f 100644
--- a/pkg/vm_service/lib/src/vm_service.dart
+++ b/pkg/vm_service/lib/src/vm_service.dart
@@ -1890,6 +1890,9 @@ class VmService {
         'Service connection disposed',
       ));
     });
+    for (var controller in _eventControllers.values) {
+      await controller.close();
+    }
     _outstandingRequests.clear();
     final handler = _disposeHandler;
     if (handler != null) {
@mraleph mraleph added area-pkg Used for miscellaneous pkg/ packages not associated with specific area- teams. pkg-dds For issues related to the Dart Development Service labels May 5, 2025
@mraleph mraleph added the type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) label May 5, 2025
@bkonyi bkonyi removed their assignment May 5, 2025
@bkonyi
Copy link
Contributor

bkonyi commented May 5, 2025

@derekxu16 can you take a look?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-pkg Used for miscellaneous pkg/ packages not associated with specific area- teams. pkg-dds For issues related to the Dart Development Service type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

3 participants