grpc / grpc-web

gRPC for Web Clients
https://grpc.io
Apache License 2.0
8.56k stars 762 forks source link

Example streaming code causes "Failed to load resource" in Safari #1188

Open mike-lerch opened 2 years ago

mike-lerch commented 2 years ago

Here is the streaming example given on this project:

var stream = echoService.serverStreamingEcho(streamRequest, metadata);
stream.on('data', function(response) {
  console.log(response.getMessage());
});
stream.on('status', function(status) {
  console.log(status.code);
  console.log(status.details);
  console.log(status.metadata);
});
stream.on('end', function(end) {
  // stream end signal
});

// to close the stream
stream.cancel()

if this code is used verbatim on Chrome, the console logs will happen as expected. However, in Safari, the request will fail and the browser will show an error such as Failed to load resource: Preflight response is no successful

It appears commenting out the last line fixes this for Safari: // stream.cancel()

It would be useful to rewrite this in a way that works in Safari, or make it clear that the stream will hang up immediately and not wait like it does in Chrome. The server-side errors logs are confusing as well, as Envoy will only show the TLS handshake failing and a client disconnect. The stream never starts.

sampajano commented 2 years ago

Hi! Thanks for the report! :)

However, i'm not quite able to reproduce the issue following your example in safari Version 15.2 (17612.3.6.1.6).

May i ask what Safari version are you using?

Also, i'm curious if you've tested on other browsers too? Is it possible that this is a Safari bug rather than grpc-web bug?

Thanks! :)