dart-lang / webdev

A CLI for Dart web development.
https://pub.dev/packages/webdev
212 stars 75 forks source link

The `streamCpuSamplesWithUserTag` method is erroneously being called from DWDS #1504

Closed elliette closed 1 year ago

elliette commented 2 years ago

The dwds/test/dart_devtools.dart test is currently failing:

Stack trace ``` 01:03 +1 -1: Injected client can not launch devtools for the same app in multiple tabs [FINEST] DevHandler: VmService proxy responded with an error: {jsonrpc: 2.0, id: 30, error: {code: -32603, message: streamCpuSamplesWithUserTag: NoSuchMethodError: Class 'ChromeProxyService' has no instance method 'streamCpuSamplesWithUserTag' with matching arguments. Receiver: Instance of 'ChromeProxyService' Tried calling: streamCpuSamplesWithUserTag(Instance(length:0) of '_GrowableList') Found: streamCpuSamplesWithUserTag(List) => Future, data: {details: #0 Object.noSuchMethod (dart:core-patch/object_patch.dart:38:5) #1 ChromeProxyService.noSuchMethod (package:dwds/src/services/chrome_proxy_service.dart:1042:18) #2 ChromeProxyService.streamCpuSamplesWithUserTag (package:dwds/src/services/chrome_proxy_service.dart:43:7) #3 VmServerConnection._delegateRequest (package:vm_service/src/vm_service.dart:1654:51) #4 StackZoneSpecification._registerUnaryCallback.. (package:stack_trace/src/stack_zone_specification.dart:126:26) #5 StackZoneSpecification._run (package:stack_trace/src/stack_zone_specification.dart:208:15) #6 StackZoneSpecification._registerUnaryCallback. (package:stack_trace/src/stack_zone_specification.dart:126:14) #7 _rootRunUnary (dart:async/zone.dart:1434:47) #8 _CustomZone.runUnary (dart:async/zone.dart:1335:19) #9 _CustomZone.runUnaryGuarded (dart:async/zone.dart:1244:7) #10 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:341:11) #11 _BufferingStreamSubscription._add (dart:async/stream_impl.dart:271:7) #12 _ForwardingStreamSubscription._add (dart:async/stream_pipe.dart:123:11) #13 _MapStream._handleData (dart:async/stream_pipe.dart:218:10) #14 _ForwardingStreamSubscription._handleData (dart:async/stream_pipe.dart:153:13) #15 StackZoneSpecification._registerUnaryCallback.. (package:stack_trace/src/stack_zone_specification.dart:126:26) #16 StackZoneSpecification._run (package:stack_trace/src/stack_zone_specification.dart:208:15) #17 StackZoneSpecification._registerUnaryCallback. (package:stack_trace/src/stack_zone_specification.dart:126:14) #18 _rootRunUnary (dart:async/zone.dart:1434:47) #19 _CustomZone.runUnary (dart:async/zone.dart:1335:19) #20 _CustomZone.runUnaryGuarded (dart:async/zone.dart:1244:7) #21 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:341:11) #22 _BufferingStreamSubscription._add (dart:async/stream_impl.dart:271:7) #23 _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:774:19) #24 _StreamController._add (dart:async/stream_controller.dart:648:7) #25 _StreamController.add (dart:async/stream_controller.dart:596:5) #26 new WebSocketImpl.fromSocket. (package:web_socket_channel/src/copy/web_socket_impl.dart:730:21) #27 StackZoneSpecification._registerUnaryCallback.. (package:stack_trace/src/stack_zone_specification.dart:126:26) #28 StackZoneSpecification._run (package:stack_trace/src/stack_zone_specification.dart:208:15) #29 StackZoneSpecification._registerUnaryCallback. (package:stack_trace/src/stack_zone_specification.dart:126:14) #30 _rootRunUnary (dart:async/zone.dart:1434:47) #31 _CustomZone.runUnary (dart:async/zone.dart:1335:19) #32 _CustomZone.runUnaryGuarded (dart:async/zone.dart:1244:7) #33 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:341:11) #34 _BufferingStreamSubscription._add (dart:async/stream_impl.dart:271:7) #35 _SinkTransformerStreamSubscription._add (dart:async/stream_transformers.dart:63:11) #36 _EventSinkWrapper.add (dart:async/stream_transformers.dart:13:11) #37 _WebSocketProtocolTransformer._messageFrameEnd (package:web_socket_channel/src/copy/web_socket_impl.dart:319:23) #38 _WebSocketProtocolTransformer.add (package:web_socket_channel/src/copy/web_socket_impl.dart:218:46) #39 _SinkTransformerStreamSubscription._handleData (dart:async/stream_transformers.dart:111:24) #40 StackZoneSpecification._registerUnaryCallback.. (package:stack_trace/src/stack_zone_specification.dart:126:26) #41 StackZoneSpecification._run (package:stack_trace/src/stack_zone_specification.dart:208:15) #42 StackZoneSpecification._registerUnaryCallback. (package:stack_trace/src/stack_zone_specification.dart:126:14) #43 _rootRunUnary (dart:async/zone.dart:1434:47) #44 _CustomZone.runUnary (dart:async/zone.dart:1335:19) #45 _CustomZone.runUnaryGuarded (dart:async/zone.dart:1244:7) #46 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:341:11) #47 _BufferingStreamSubscription._add (dart:async/stream_impl.dart:271:7) #48 _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:774:19) #49 _StreamController._add (dart:async/stream_controller.dart:648:7) #50 _StreamController.add (dart:async/stream_controller.dart:596:5) #51 _Socket._onData (dart:io-patch/socket_patch.dart:2314:41) #52 StackZoneSpecification._registerUnaryCallback.. (package:stack_trace/src/stack_zone_specification.dart:126:26) #53 StackZoneSpecification._run (package:stack_trace/src/stack_zone_specification.dart:208:15) #54 StackZoneSpecification._registerUnaryCallback. (package:stack_trace/src/stack_zone_specification.dart:126:14) #55 _rootRunUnary (dart:async/zone.dart:1442:13) #56 _CustomZone.runUnary (dart:async/zone.dart:1335:19) #57 _CustomZone.runUnaryGuarded (dart:async/zone.dart:1244:7) #58 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:341:11) #59 _BufferingStreamSubscription._add (dart:async/stream_impl.dart:271:7) #60 _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:774:19) #61 _StreamController._add (dart:async/stream_controller.dart:648:7) #62 _StreamController.add (dart:async/stream_controller.dart:596:5) #63 new _RawSocket. (dart:io-patch/socket_patch.dart:1839:33) #64 _NativeSocket.issueReadEvent.issue (dart:io-patch/socket_patch.dart:1322:14) #65 _microtaskLoop (dart:async/schedule_microtask.dart:40:21) #66 _startMicrotaskLoop (dart:async/schedule_microtask.dart:49:5) #67 _runPendingImmediateCallback (dart:isolate-patch/isolate_patch.dart:122:13) #68 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:193:5) }}} ```

It looks like this is due to the change to VM Service adding the streamCpuSamplesWithUserTag method: https://github.com/dart-lang/sdk/commit/0c071662a770cbfe7f6768a791fafaa7a5e48654

However, it is unclear to me why that method is being called from DWDS.

elliette commented 2 years ago

Re-assigning to Anna since you have a fix, thanks!

elliette commented 2 years ago

Adding @bkonyi for input here.

Would it be possible for DDS to catch any errors if the VM doesn't implement the method (similarly to what you are did in https://dart-review.googlesource.com/c/sdk/+/227620 for _setStreamIncludePrivateMembers)?

It looks like we are still encountering the same issue with https://github.com/dart-lang/webdev/pull/1507, with @annagrin explicitly overriding the method.

Thanks!

bkonyi commented 2 years ago

Adding @bkonyi for input here.

Would it be possible for DDS to catch any errors if the VM doesn't implement the method (similarly to what you are did in https://dart-review.googlesource.com/c/sdk/+/227620 for _setStreamIncludePrivateMembers)?

No, that's probably not the right thing to do. _setStreamIncludePrivateMembers was a bit of a special case. We should be notifying clients that the RPC is unimplemented in this case. Maybe update the noSuchMethod implementation to throw UnimplementedError?

elliette commented 2 years ago

@DanTup just encountered this error as well when debugging from VSCode.

@bkonyi - is it possible that this check for cachedUserTags isn't working as expected, causing the streamCpuSamplesWithUserTag to be invoked, even when the client (Dart DevTools, VSCode, etc) hasn't explicitly invoked it themselves?

bkonyi commented 2 years ago

No, it's not currently passed by any tools that spawn DDS, so that list is always empty right now. Are you on the most recent version of Dart/Flutter?

DanTup commented 2 years ago

I was using latest Flutter master from an hour or two ago. I was running from VS Code using the web-server device and the Dart Debug extension, although I just triggered it again using the Chrome device.

Here's what I did:

After closing the window, I see this in the debug console:

[+15212 ms] DevHandler: VmService proxy responded with an error:
            {jsonrpc: 2.0, id: 72, error: {code: -32603, message: streamCpuSamplesWithUserTag: NoSuchMethodError: Class 'ChromeProxyService' has no instance method 'streamCpuSamplesWithUserTag' with matching arguments.
            Receiver: Instance of 'ChromeProxyService'
            Tried calling: streamCpuSamplesWithUserTag(Instance(length:0) of '_GrowableList')
Found: streamCpuSamplesWithUserTag(List<String>) => Future<Success>, data: {details: #0      Object.noSuchMethod (dart:core-patch/object_patch.dart:38:5)
#1      ChromeProxyService.noSuchMethod (package:dwds/src/services/chrome_proxy_service.dart:1042:18)
#2      ChromeProxyService.streamCpuSamplesWithUserTag (package:dwds/src/services/chrome_proxy_service.dart:43:7)
#3      VmServerConnection._delegateRequest (package:vm_service/src/vm_service.dart:1654:51)
#4      StackZoneSpecification._registerUnaryCallback.<anonymous closure>.<anonymous closure>
#5      StackZoneSpecification._run
#6      StackZoneSpecification._registerUnaryCallback.<anonymous closure>
#7      _rootRunUnary (dart:async/zone.dart:1434:47)
#8      _CustomZone.runUnary (dart:async/zone.dart:1335:19)
#9      _CustomZone.runUnaryGuarded (dart:async/zone.dart:1244:7)
#10     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:341:11)
#11     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:271:7)
#12     _ForwardingStreamSubscription._add (dart:async/stream_pipe.dart:123:11)
#13     _MapStream._handleData (dart:async/stream_pipe.dart:218:10)
#14     _ForwardingStreamSubscription._handleData (dart:async/stream_pipe.dart:153:13)
#15     StackZoneSpecification._registerUnaryCallback.<anonymous closure>.<anonymous closure>
#16     StackZoneSpecification._run
#17     StackZoneSpecification._registerUnaryCallback.<anonymous closure>
#18     _rootRunUnary (dart:async/zone.dart:1434:47)
#19     _CustomZone.runUnary (dart:async/zone.dart:1335:19)
#20     _CustomZone.runUnaryGuarded (dart:async/zone.dart:1244:7)
#21     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:341:11)
#22     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:271:7)
#23     _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:774:19)
#24     _StreamController._add (dart:async/stream_controller.dart:648:7)
#25     _StreamController.add (dart:async/stream_controller.dart:596:5)
#26     new WebSocketImpl.fromSocket.<anonymous closure> (package:web_socket_channel/src/copy/web_socket_impl.dart:730:21)
#27     StackZoneSpecification._registerUnaryCallback.<anonymous closure>.<anonymous closure>
#28     StackZoneSpecification._run
#29     StackZoneSpecification._registerUnaryCallback.<anonymous closure>
#30     _rootRunUnary (dart:async/zone.dart:1434:47)
#31     _CustomZone.runUnary (dart:async/zone.dart:1335:19)
#32     _CustomZone.runUnaryGuarded (dart:async/zone.dart:1244:7)
#33     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:341:11)
#34     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:271:7)
#35     _SinkTransformerStreamSubscription._add (dart:async/stream_transformers.dart:63:11)
#36     _EventSinkWrapper.add (dart:async/stream_transformers.dart:13:11)
#37     _WebSocketProtocolTransformer._messageFrameEnd (package:web_socket_channel/src/copy/web_socket_impl.dart:319:23)
#38     _WebSocketProtocolTransformer.add (package:web_socket_channel/src/copy/web_socket_impl.dart:218:46)
#39     _SinkTransformerStreamSubscription._handleData (dart:async/stream_transformers.dart:111:24)
#40     StackZoneSpecification._registerUnaryCallback.<anonymous closure>.<anonymous closure>
#41     StackZoneSpecification._run
#42     StackZoneSpecification._registerUnaryCallback.<anonymous closure>
#43     _rootRunUnary (dart:async/zone.dart:1434:47)
#44     _CustomZone.runUnary (dart:async/zone.dart:1335:19)
#45     _CustomZone.runUnaryGuarded (dart:async/zone.dart:1244:7)
#46     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:341:11)
#47     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:271:7)
#48     _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:774:19)
#49     _StreamController._add (dart:async/stream_controller.dart:648:7)
#50     _StreamController.add (dart:async/stream_controller.dart:596:5)
#51     _Socket._onData (dart:io-patch/socket_patch.dart:2314:41)
#52     StackZoneSpecification._registerUnaryCallback.<anonymous closure>.<anonymous closure>
#53     StackZoneSpecification._run
#54     StackZoneSpecification._registerUnaryCallback.<anonymous closure>
#55     _rootRunUnary (dart:async/zone.dart:1442:13)
#56     _CustomZone.runUnary (dart:async/zone.dart:1335:19)
#57     _CustomZone.runUnaryGuarded (dart:async/zone.dart:1244:7)
#58     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:341:11)
#59     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:271:7)
#60     _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:774:19)
#61     _StreamController._add (dart:async/stream_controller.dart:648:7)
#62     _StreamController.add (dart:async/stream_controller.dart:596:5)
#63     new _RawSocket.<anonymous closure> (dart:io-patch/socket_patch.dart:1839:33)
#64     _NativeSocket.issueReadEvent.issue (dart:io-patch/socket_patch.dart:1322:14)
#65     _microtaskLoop (dart:async/schedule_microtask.dart:40:21)
#66     _startMicrotaskLoop (dart:async/schedule_microtask.dart:49:5)
#67     _runPendingImmediateCallback (dart:isolate-patch/isolate_patch.dart:122:13)
#68     _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:193:5)
            }}}

I'm not sure if it's related, but I also saw some other errors prior to opening DevTools/inspector:

[        ] DevHandler: VmService proxy responded with an error:
           {jsonrpc: 2.0, id: 43, error: {code: -32601, message: Method not found, data: {jsonrpc: 2.0, method: _setStreamIncludePrivateMembers, id: 43, params: {streamId: Stdout, includePrivateMembers: false}}}}
bkonyi commented 2 years ago

Does this happen consistently? I'm not able to reproduce with devtools_test.dart

DanTup commented 2 years ago

Yep, and I can reproduce without VS Code (although, I only see it show up when running with --verbose).

I'm using:

danny@Dannys-MacBook-Pro flutter_debug_web % flutter --version
Flutter 2.11.0-0.0.pre.886 • channel master • git@github.com:DanTup/flutter.git
Framework • revision 2bd3e0d914 (10 hours ago) • 2022-03-15 04:20:15 -0400
Engine • revision 6c02eaea3a
Tools • Dart 2.17.0 (build 2.17.0-202.0.dev) • DevTools 2.11.4

As soon as I close DevTools, the error is printed to the terminal (in verbose mode).

bkonyi commented 2 years ago

Okay, I see what's happening now. DDS makes these requests and has error handlers for the case where the target service doesn't have an implementation. streamCpuSamplesWithUserTag is invoked unconditionally when a client disconnects to ensure state is kept up to date, which is why we're seeing the exception printed when DevTools closes.

DWDS should probably only return an error response instead of logging the exception as it's not a fatal error and a bad request from a client shouldn't be treated the same as one.