Commit Graph

82 Commits

Author SHA1 Message Date
Ben Konyi 34a6218f8e [ VM / Service ] Forward message for exceptions caught in VM service PUT requests
Fixes #36202

Change-Id: If578ec8e24a5acf10db85a7f17cc98a0b7168c57
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/105475
Commit-Queue: Ben Konyi <bkonyi@google.com>
Reviewed-by: Siva Annamalai <asiva@google.com>
2019-06-11 16:15:23 +00:00
Ben Konyi ded5c3efd5 [ VM / Service ] Fixed HTTP requests with params not working correctly when auth codes are enabled
Change-Id: Ia6dbab2c8e46cdd1fce659f55ee16f3ad98e5d6d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/101021
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Ben Konyi <bkonyi@google.com>
2019-05-02 17:38:49 +00:00
Ben Konyi 24396182e1 [ VM / Service ] Handle case where user navigates to Observatory without a slash trailing the authentication code.
Previously, navigating to an observatory URI similar to http://127.0.0.1:8181/KUhS6KoCm24=
would result in a missing auth code error. This change explicitly checks
for this case and issues a redirect response to
http://127.0.0.1:8181/KUhS6KoCm24=/ so index.html can be sent properly
in the follow up request.

Fixes #36763

Change-Id: I8a73f2ef08f6bf1ca5aed4ddaaf97ae3489f7e23
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/100631
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Ben Konyi <bkonyi@google.com>
2019-04-29 17:03:49 +00:00
Ben Konyi 92c9f124c3 [ VM / Service ] Fixed HTTP requests to the VM service not working correctly with authentication codes
Change-Id: Ibbf9edb58b9e1f83b31ff876d2da4ef327ea1dab
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/99081
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Ben Konyi <bkonyi@google.com>
2019-04-10 19:41:59 +00:00
Ben Konyi 15b11b0183 [ VM / Service / Observatory ] The VM service now requires an authentication code by default.
Previously, a valid web socket connection would use the following URI:

`ws://127.0.0.1/ws`

Now, by default, the VM service requires a connection to be made with a
URI similar to the following:

`ws://127.0.0.1:8181/Ug_U0QVsqFs=/ws`

where `Ug_U0QVsqFs` is an authentication code generated and shared by the
service.

This behavior can be disabled with the `--disable-service-auth-codes`
flag.

Change-Id: I288aac58e3ba9d35dca8071f3f7e7a073896c271
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/98433
Commit-Queue: Ben Konyi <bkonyi@google.com>
Reviewed-by: Siva Annamalai <asiva@google.com>
2019-04-09 22:57:29 +00:00
Ben Konyi ff6f61c872 [VM / Observatory ] Remove needless stacktrace print when adding to closed socket
Change-Id: Idc31b45fd880ff0233c7cbeb31a22d43fbcea01e
Reviewed-on: https://dart-review.googlesource.com/c/94840
Commit-Queue: Ben Konyi <bkonyi@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Auto-Submit: Ben Konyi <bkonyi@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2019-02-28 18:35:03 +00:00
asiva 763589472e [VM / vmservice] - Change setting of silentObservatory to a non const expression
Change-Id: I89d72c05fd897fcf1396585132d4056c4e91195d
Reviewed-on: https://dart-review.googlesource.com/c/93361
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Siva Annamalai <asiva@google.com>
2019-02-15 02:46:41 +00:00
Jonas Finnemann Jensen 8146725731 Return 403 and 405 from observatory server
With this change untrusted `origin` header or method not allowed will
return 403 and 405 respectively. Before this change it returned 200 with
an empty body. Returning proper error codes helps users debug their
setup and figure out what is wrong.

Closes https://github.com/dart-lang/sdk/issues/34121

Change-Id: I60c75ee2e33882f98fd9a020d33d459e74febf29
Reviewed-on: https://dart-review.googlesource.com/c/69308
Commit-Queue: Jonas Jensen <jonasfj@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2018-11-08 17:03:11 +00:00
asiva e6d3a45b6a [VM] Fix for issue 34839 Service isolate hangs during shutdown if
the VM exits before the Observatory server has a chance to
     start listening.

Bug: 34839
Change-Id: I2a5dfe69a197fe054dd041af3ea4e07da736b226
Reviewed-on: https://dart-review.googlesource.com/c/81381
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Siva Annamalai <asiva@google.com>
2018-10-27 00:45:59 +00:00
Vyacheslav Egorov b2eab8b96e [VM/Service] Restore zero-copying handling of JSON messages in vmservice.
In 5a44162c97 in attempt to adhere to declared
method signatures we lost zero-copying JSON decoding of responses from
VM: `Message.sendToVM` was changed to always decode the response into
string before passing it to the caller and the logic to use fused
JSON decoding was removed. This increased peak memory consumption by
the VM Service.

This commit addresses the issue by restoring the zero-copying JSON decoding
logic while adding a wrapper around responses that make it clear what kind
of data is passed around and how that data is encoded and handled.

We introduce a class `Response` which can contain either a Dart string, a
binary data (represented as a Uint8List) or utf8 encoded string (represented
as a Uint8List). This class is used in all places where previously a String
or dynamic were used, e.g. MessageRouter.routeRequest is changed to return
Future<Response> rather than Future<String>. This allows callees to
decode JSON responses without copying them into Dart heap while
maintaining sufficient level of typing to make the code easy to reason about.

This commit also removes some dead code from the VM service related to old
Service API and TAR assets unpacking (which has been long done in C++).

Bug: https://github.com/flutter/flutter/issues/13626
Change-Id: Ifbba56944a552034a0f802a965a313326a1236e7
Reviewed-on: https://dart-review.googlesource.com/30280
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Vyacheslav Egorov <vegorov@google.com>
2017-12-18 19:06:06 +00:00
Lasse R.H. Nielsen 0b58c4bd10 Change some constant declarations to lowerCase.
Retain the old values.

Reapply of https://dart-review.googlesource.com/c/sdk/+/20680 with fixes
for VM method fingerprints.

Change-Id: Ie14e7ccc3194d5561983348e6b6752728913ff4d
Reviewed-on: https://dart-review.googlesource.com/20664
Reviewed-by: Erik Ernst <eernst@google.com>
Commit-Queue: Lasse R.H. Nielsen <lrn@google.com>
2017-11-14 12:59:14 +00:00
Lasse R.H. Nielsen e61fc07b58 Revert "Change some constant declarations to lowerCase."
This reverts commit c048cfb178.

Reason for revert: VM code fingerprints needs update.

Original change's description:
> Change some constant declarations to lowerCase.
> 
> Retain the old values.
> 
> Change-Id: I03bd326f379fe5f96d8f6081a7133de956d745c0
> Reviewed-on: https://dart-review.googlesource.com/11520
> Commit-Queue: Lasse R.H. Nielsen <lrn@google.com>
> Reviewed-by: Florian Loitsch <floitsch@google.com>

TBR=lrn@google.com,floitsch@google.com

Change-Id: I095e8198304ca4e59b39d30b0fdf0af4945e5231
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://dart-review.googlesource.com/20680
Reviewed-by: Lasse R.H. Nielsen <lrn@google.com>
Commit-Queue: Lasse R.H. Nielsen <lrn@google.com>
2017-11-14 11:23:08 +00:00
Lasse R.H. Nielsen c048cfb178 Change some constant declarations to lowerCase.
Retain the old values.

Change-Id: I03bd326f379fe5f96d8f6081a7133de956d745c0
Reviewed-on: https://dart-review.googlesource.com/11520
Commit-Queue: Lasse R.H. Nielsen <lrn@google.com>
Reviewed-by: Florian Loitsch <floitsch@google.com>
2017-11-14 11:13:04 +00:00
Zachary Anderson 08f2633022 [Fuchsia] Remove vm service hacks
Change-Id: Ia012ed493dc15f847db2b8798435944dff637c8e
Reviewed-on: https://dart-review.googlesource.com/7441
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2017-09-21 15:00:39 +00:00
Carlo Bernaschina df8bf384eb Introduce external services registration
A new RPC is introduced `_registerService` which allow clients to
register new services that are accessible from all the other clients.

Each registered endpoint is identified by 3 strings:

 - `service`
   a non empty string which identifies the provided service
   (e.g. `HotReload`, `OpenFile`)
 - `alias`
   an alias for that particular endpoint used by clients to identify it
   (e.g. `Flutter`, `IntelliJ`)
 - `method` __generated__
   the RPC method that should be invoked from a client to request it

A new _stream_ `_Service` is introduce, and two related events:

 - `ServiceRegistered`
   which is triggered when a new client is registered.
   All the related information (`service`, `alias`, `method`) are sent.

 - `ServiceUnregistered`
   which is triggered when a client, which previously registered a
   service, disconnects.
   Just `service` and `method` are sent.

Related https://github.com/dart-lang/sdk/issues/30023

R=asiva@google.com, bkonyi@google.com

Review-Url: https://codereview.chromium.org/2980733003 .
2017-07-13 18:18:51 -07:00
Zachary Anderson d6cc48b8e1 [Fuchsia] Switch service protocol to bind to ipv6
This should work now.

R=rmacnak@google.com

Review-Url: https://codereview.chromium.org/2842783002 .
2017-04-25 09:53:49 -07:00
Jacob Richman b67e83eea3 Format all remaining unformatted runtime files other than multitests.
BUG=
R=johnmccutchan@google.com

Review-Url: https://codereview.chromium.org/2829463003 .
2017-04-18 15:34:03 -07:00
Ryan Macnak d0529c8638 Nicer message when attempting to use Observatory from dart_bootstrap, dart_precompiled_runtime or an unnamed badly configured build.
R=johnmccutchan@google.com

Review-Url: https://codereview.chromium.org/2793603002 .
2017-03-31 13:29:52 -07:00
Zachary Anderson 6f45ea2247 [vm service] Have HTTP server retry binding for 10 seconds
This is for Fuchsia, where Flutter apps may start before the network
stack has finished initializing.

R=johnmccutchan@google.com

Review-Url: https://codereview.chromium.org/2772463003 .
2017-03-22 14:20:39 -07:00
Jacob Richman 4360e99d18 Revert "Fix observatory tests broken by running dartfmt."
This reverts commit b1f7e6d94673b098c93c187fe3efc45c15f27edc.

BUG=

Committed: https://github.com/dart-lang/sdk/commit/62be0eacfbb36bdc92a05c7c35bb4506621b6a3a
Review-Url: https://codereview.chromium.org/2767533002 .
2017-03-21 10:07:26 -07:00
Jacob Richman 62be0eacfb Revert "Fix observatory tests broken by running dartfmt."
This reverts commit b1f7e6d94673b098c93c187fe3efc45c15f27edc.

BUG=

Review-Url: https://codereview.chromium.org/2767533002 .
2017-03-20 22:19:22 -07:00
Jacob Richman 88f8aacd5f Re-apply rolled back CL to apply dartfmt to runtime.
Fix observatory tests broken by running dartfmt due to line and column changes.
Temporarily reverted formatting for evaluate_activation_test.dart as dartfmt doesn't yet handle multitests.

BUG=
R=johnmccutchan@google.com

Review-Url: https://codereview.chromium.org/2759973004 .
2017-03-20 21:44:59 -07:00
Ryan Macnak ea4744a06f Revert "Run dartfmt on all files under runtime."
This reverts commit 15f393f189.

The change caused many service test failures due to changed line numbers.

TBR=jacobr@google.com

Review-Url: https://codereview.chromium.org/2762583003 .
2017-03-20 13:42:55 -07:00
Jacob Richman 15f393f189 Run dartfmt on all files under runtime.
I've omitted files where the formatter output is significantly uglier
than the original code and I'll send those files in a separate CL
with options for how to make the code look reasonable while still
taking advantage of the formatter.

BUG=
R=johnmccutchan@google.com

Review-Url: https://codereview.chromium.org/2751423005 .
2017-03-20 13:13:50 -07:00
Zachary Anderson 2388040784 [Fuchsia] vmservice creates a file in /tmp named with its port.
This is to allow the flutter_tool to quickly query a Fuchsia
device for the open vmservice ports.

R=johnmccutchan@google.com

Review-Url: https://codereview.chromium.org/2738373003 .
2017-03-10 14:32:38 -08:00
Zachary Anderson e73edbc5d1 [Fuchsia] Bind Observatory to ipv4 any
Also fix a command line argument for creating the test image.

R=johnmccutchan@google.com

Review-Url: https://codereview.chromium.org/2740203002 .
2017-03-09 12:50:41 -08:00
John McCutchan 5128636521 Support DevFS paths encoded as URIs
Fixes #28972

Note that the path handling logic in DevFS is now complicated with three
possible sources of path information. After we roll this we should clean it
up and unify on Uri encoding

BUG=
R=turnidge@google.com

Review-Url: https://codereview.chromium.org/2733413003 .
2017-03-08 15:41:11 -08:00
John McCutchan 7e55c12e03 Add SILENT_OBSERVATORY environment variable to Observatory web server
BUG=
R=rmacnak@google.com

Review-Url: https://codereview.chromium.org/2715423002 .
2017-02-28 07:33:33 -08:00
Zachary Anderson 6f9dcaff9d Fuchsia: Disable service origin check. Bind service to all interfaces.
R=asiva@google.com

Review-Url: https://codereview.chromium.org/2626043006 .
2017-01-13 12:27:17 -08:00
Ryan Macnak 1b51889447 Allow binding the vm service to IPv6 addresses.
Change the default bind address to 'localhost', which will be resolved to '127.0.0.1' or '::1' depending on the host's support for IPv6.

Fixes #27841

R=johnmccutchan@google.com

Review URL: https://codereview.chromium.org/2515023002 .
2016-11-23 14:24:52 -08:00
Siva Annamalai 4a9cc3e5fe Fix test breakage in checked mode.
BUG=
R=rmacnak@google.com

Review URL: https://codereview.chromium.org/2497693002 .
2016-11-11 15:01:32 -08:00
John McCutchan 63e4f69e5e Provide an API to dart:developer to control the web server hosting the Service Protocol
- [x] Add `ServiceProtocolnfo` class to dart:developer.
- [x] Add `Service` class to dart:developer.
- [x] Add `Service.getInfo` static method to dart:developer.
- [x] Add `Service.controlWebServer` static method to dart:developer.

API:

```dart

/// Information about the service protocol.
class ServiceProtocolInfo {
  /// The major version of the protocol.
  final int majorVersion;
  /// The minor version of the protocol.
  final int minorVersion;
  /// The Uri to access the service. If the web server is not running, this
  /// will be null.
  final Uri serverUri;
}

/// Access information about the service protocol and control the web server.
class Service {
  /// Get information about the service protocol.
  static Future<ServiceProtocolInfo> getInfo();

  /// Control the web server that the service protocol is accessed through.
  static Future<ServiceProtocolInfo> controlWebServer({bool enable: false});
}
```

... and add a randomly generated authentication token path prefix that must be passed in to access the service protocol.

Old base url:

Observatory listening on http://127.0.0.1:54804/

New base url:

Observatory listening on http://127.0.0.1:54804/<token>/

For example:

Observatory listening on http://127.0.0.1:54804/PTwjm8Ii8qg=/

Many tools will need to be updated.

Fixes #23320

BUG=
R=asiva@google.com, rmacnak@google.com

Review URL: https://codereview.chromium.org/2438613002 .
2016-10-31 12:32:23 -07:00
John McCutchan 8b37da82ef Support paths which are encoded with base64 in http put devfs server code
- [x] Add a new header 'dev_fs_path_b64' which is used over 'dev_fs_path' when present.
- [x] 'dev_fs_path_b64' expects the path encoded as UTF8 and then BASE64.
- [x] Add unit test case.

BUG=
R=turnidge@google.com

Review URL: https://codereview.chromium.org/2386123005 .
2016-10-04 15:31:09 -07:00
Ryan Macnak fcda790b9c Fix bad origin check.
localhost.malicious.com is not localhost.

R=johnmccutchan@google.com

Review URL: https://codereview.chromium.org/2298943004 .
2016-09-09 16:34:03 -07:00
Carlo Bernaschina 4b328e442f Added service protocol cross-origin access from localhost for http requests
Related to https://github.com/dart-lang/sdk/commit/e6e61332d6ec7c3bd6c92fa7496282174db521a7

R=rmacnak@google.com

Review URL: https://codereview.chromium.org/2308083002 .
2016-09-02 13:59:56 -07:00
Carlo Bernaschina 62114cee60 Added service protocol cross-origin access from localhost for http requests
Related to https://github.com/dart-lang/sdk/commit/e6e61332d6ec7c3bd6c92fa7496282174db521a7

R=rmacnak@google.com

Review URL: https://codereview.chromium.org/2295343006 .
2016-09-02 11:17:11 -07:00
Carlo Bernaschina 7bdb33a766 Log exceptions in vmservice post()
Fixes=https://github.com/dart-lang/sdk/issues/27172

R=rmacnak@google.com

Review URL: https://codereview.chromium.org/2287603004 .
2016-08-26 15:36:31 -07:00
Ryan Macnak aa38062a23 Add WebSocket.addUtf8Text to allow sending pre-encoded text without a round-trip UTF-8 conversion.
Use it to implement the vm-service, where in particular we are concerned about the space overhead of the conversion leading to the process being killed on iOS.

Closes #27129

R=johnmccutchan@google.com, lrn@google.com

Review URL: https://codereview.chromium.org/2260073002 .
2016-08-24 16:15:07 -07:00
Ryan Macnak d418dde65b Reduce copying in sending service responses.
Add missing safepoint transitions.

Issue #27092
Likely contributes to Issue #27010

dart2js hello
Peak RSS at first Observatory visit -> Peak RSS after visiting timeline (with endless recorder)
Before 215M -> 321M
After 182M -> 233M

R=johnmccutchan@google.com

Review URL: https://codereview.chromium.org/2254543006 .
2016-08-18 10:34:50 -07:00
John McCutchan a67b9c82ee Support devFS writes via HTTP PUT
- [x] Allow DevFS writes over HTTP PUT with a gzip compressed payload.
- [x] Add service test for http put writes.

BUG=
R=rmacnak@google.com

Review URL: https://codereview.chromium.org/2225583002 .
2016-08-08 10:35:29 -07:00
John McCutchan a458f45a02 Enable WebSocket compression for the service protocol
BUG=
R=rmacnak@google.com

Review URL: https://codereview.chromium.org/2184793002 .
2016-07-26 15:25:05 -07:00
John McCutchan e6e61332d6 Relax service protocol origin check to allow connections from localhost on any port.
This is necessary because adb port forwarding will give us a different port than the port bound on the actual device.

BUG=
R=asiva@google.com

Review URL: https://codereview.chromium.org/2146613002 .
2016-07-12 13:27:01 -07:00
John McCutchan af85432e28 Ban cross origin WebSocket connections to the service protocol.
- Explicitly allow connections from localhost/127.0.0.1 and the server's ip address and host name.

- This has the negative effect of breaking our Dartium work flow, so, I've added the "--disable-service-origin-check" flag to the standalone embedder which disables the security check.

R=asiva@google.com

Review URL: https://codereview.chromium.org/2125343002 .
2016-07-07 12:14:54 -07:00
John McCutchan 87d8d3a719 Make it possible to share the embedder's dart sources for the service isolate.
- Cleanups to the embedder's Dart sources for the service isolate. This lets us stop keeping a local copy in the mojo and flutter trees.
- Let the VM know Observatory's server address.

R=zra@google.com

Review URL: https://codereview.chromium.org/1640773005 .
2016-01-29 07:43:21 -08:00
John McCutchan 019f89507a Fix Observatory by disabling WebSocket compression
BUG=

Review URL: https://codereview.chromium.org/1430333002 .
2015-11-09 13:27:03 -08:00
John McCutchan 2844eb86ca Service isolate requests Observatory assets from embedder
- Provide a new callback to Dart_Initialize that will be called when the service isolate needs the Observatory assets
- Move asset management code out of embedder and into common dart:_vmservice
- Use the tar format as the archive format
- Add build script to generate .cc file containing the archive
- Add a simple tar parser to service isolate

This makes it possible for embedders to not bake Observatory into their executable but instead load it off disk or over the network. The standalone embedder still links Observatory into the executable.

R=rmacnak@google.com

Review URL: https://codereview.chromium.org/1411853003 .
2015-10-26 07:21:23 -07:00
John McCutchan f6e0a8f30b Catch unexpected http uri error in service isolate
Fixes #24388

R=iposva@google.com

Review URL: https://codereview.chromium.org//1357023004 .
2015-09-21 11:01:34 -07:00
John McCutchan ae57de89d1 Force disconnect all service clients when VM is shutting down
BUG=https://github.com/dart-lang/sdk/issues/24352
R=turnidge@google.com

Review URL: https://codereview.chromium.org//1338753004 .
2015-09-15 12:47:28 -07:00
John McCutchan 590557dfd0 When no service response is requested, send null back to the service isolate so it can cleanup
BUG=
R=turnidge@google.com

Review URL: https://codereview.chromium.org//1285673003 .
2015-08-11 07:13:09 -07:00
John McCutchan fc2d849cd5 Fix http requests and the crash dump RPC
- Fix HTTP and crash dump service requests by giving them a non-null id.
- Add basic heartbeat test for _getCrashDump RPC over HTTP.
- Fix some analyzer warnings.

R=rmacnak@google.com

Review URL: https://codereview.chromium.org//1266943005 .
2015-07-31 14:38:04 -07:00