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

Breaking change introduced in 2.4.0 grpc-web flutter #380

Closed
long1eu opened this issue Nov 2, 2020 · 6 comments · Fixed by #397
Closed

Breaking change introduced in 2.4.0 grpc-web flutter #380

long1eu opened this issue Nov 2, 2020 · 6 comments · Fixed by #397

Comments

@long1eu
Copy link

long1eu commented Nov 2, 2020

Using a commit after bb4eab0 generates this error. Seems like something changed in the way the request is made. I'm assuming is the headers.

I tried this against a local envoy proxy and with Google Cloud Run with ESPv2(envoy).

errors.dart:167 Uncaught Error: Bad state: Cannot add event after closing
    at Object.throw_ [as throw] (errors.dart:216)
    at _AsyncStreamController.new.addError (stream_controller.dart:633)
    at ClientCall.new.[_onRequestError] (call.dart:370)
    at xhr_transport.dart:71
    at Object._checkAndCall (operations.dart:324)
    at Object.dcall (operations.dart:329)
    at XMLHttpRequest.<anonymous> (html_dart2js.dart:37283)
    at xhr_transport.XhrTransportStream.new.terminate (xhr_transport.dart:148)
    at terminate.next (<anonymous>)
    at runBody (async_patch.dart:84)
    at Object._async [as async] (async_patch.dart:123)
    at xhr_transport.XhrTransportStream.new.terminate (xhr_transport.dart:146)
    at ClientCall.new.[_onRequestError] (call.dart:375)
    at xhr_transport.XhrTransportStream.new.[_onHeadersReceived] (xhr_transport.dart:116)
    at xhr_transport.dart:67
    at Object._checkAndCall (operations.dart:324)
    at Object.dcall (operations.dart:329)
    at XMLHttpRequest.<anonymous> (html_dart2js.dart:37283)

grpc web init:

// File created by
// Lung Razvan <long1eu>
// on 16/04/2020

import 'package:firebase/firebase.dart';
import 'package:grpc/grpc_web.dart' as js;
import 'package:grpc/src/client/channel.dart' show ClientChannel;

import 'init.dart' as base;

export 'package:grpc/grpc_web.dart' show CallOptions;
export 'package:grpc/src/client/channel.dart' show ClientChannel;

class InitConfig implements base.InitConfig {
  const InitConfig();

  @override
  ClientChannel get channel {
    if (Config.location == 'cloud') {
      return js.GrpcWebClientChannel.xhr(Uri.parse('https://${Config.endpoint}'));
    } else {
      return js.GrpcWebClientChannel.xhr(Uri.parse('http://localhost:8081'));
    }
  }

  @override
  js.CallOptions get options {
    return js.CallOptions(
      metadata: <String, String>{
        'x-api-key': '<key>',
      },
      providers: <js.MetadataProvider>[
        (Map<String, String> metadata, String url) async {
          if (app().auth().currentUser != null) {
            final String token = await app().auth().currentUser.getIdToken();
            metadata['authorization'] = 'Bearer $token';
          }
        },
      ],
    );
  }
}

Let me know if there is anything I can do to help identifying the bug and fixing it.
Thanks

@mraleph
Copy link
Member

mraleph commented Nov 2, 2020

@long1eu
Copy link
Author

long1eu commented Nov 2, 2020

I've removed this from lib/src/client/transport/xhr_transport.dart

    request.setRequestHeader('Content-Type', 'application/grpc-web+proto');
    request.setRequestHeader('X-User-Agent', 'grpc-web-dart/0.1');
    request.setRequestHeader('X-Grpc-Web', '1');

But the result is the same.

@long1eu
Copy link
Author

long1eu commented Nov 2, 2020

UPDATE: It does work.

My fault. Seems like I've remove them from the pub version, not the one that I was actually using.

@mraleph
Copy link
Member

mraleph commented Nov 5, 2020

We are going to revert offending change and publish a fixed version of the package, but most likely this is not going to happen earlier than next week.

I am also going to switch to envoy proxy for testing instead of grpcwebproxy, because it turns out that grpcwebproxy is too lax and did not catch this bug.

mraleph added a commit to mraleph/grpc-dart that referenced this issue Nov 11, 2020
@mraleph
Copy link
Member

mraleph commented Nov 13, 2020

We have published 2.8.0 which fixes the issue and we have switched our testing to use envoy proxy to catch this sort of errors earlier.

@mraleph

This comment has been minimized.

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

Successfully merging a pull request may close this issue.

2 participants