Stream breaks with invalid frame byte error
My grpc web client connects to a grpc server via Envoy. It uses a stream to get continuous data and update the UI, but the stream always breaks sooner or later with these errors in the following order.
- First error: Unknown base64 encoding error. The character is sometimes different.
Uncaught Error: Unknown base64 encoding at char: �
at o (engine.js:46)
at Object.goog.crypt.base64.decodeStringInternal_ (engine.js:46)
at Object.goog.crypt.base64.decodeStringToUint8Array (engine.js:46)
at goog.net.XhrIo.<anonymous> (engine.js:46)
at goog.net.XhrIo.goog.events.EventTarget.fireListeners (engine.js:46)
at Function.goog.events.EventTarget.dispatchEventInternal_ (engine.js:46)
at goog.net.XhrIo.goog.events.EventTarget.dispatchEvent (engine.js:46)
at goog.net.XhrIo.onReadyStateChangeHelper_ (engine.js:46)
at goog.net.XhrIo.onReadyStateChangeEntryPoint_ (engine.js:46)
at goog.net.XhrIo.onReadyStateChange_ (engine.js:46)
- Followed by this second error: Invalid frame byte.
Uncaught Error: The stream is broken @2708513/0. Error: invalid frame byte. With input:
19,64,0,0,0,86,80,174,32,162,128,67,45,208,160,141,27,121,41,88,226,
209,41,64,175,253,143,254,0,1,4,164,100,148,96,0,16,16,0,0,16
..................(a lot of these numbers)......
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,255,253,145,161,115,35,3,19,146,211,3,34,211,19,34,3,35,35,163,35,115,163,67,18,227,83,83,114,34,67,147,70,54,19,131,115,22,34,214,19,83,3,2,211,70,67,67,18,211,147,147,102,18,211,83,99,35,99,115,38,35,102,83,54
at module$contents$grpc$web$GrpcWebStreamParser_GrpcWebStreamParser.module$contents$grpc$web$GrpcWebStreamParser_Parser.error_ (engine.js:46)
at t (engine.js:46)
at module$contents$grpc$web$GrpcWebStreamParser_GrpcWebStreamParser.parse (engine.js:46)
at goog.net.XhrIo.<anonymous> (engine.js:46)
at goog.net.XhrIo.goog.events.EventTarget.fireListeners (engine.js:46)
at Function.goog.events.EventTarget.dispatchEventInternal_ (engine.js:46)
at goog.net.XhrIo.goog.events.EventTarget.dispatchEvent (engine.js:46)
at goog.net.XhrIo.onReadyStateChangeHelper_ (engine.js:46)
at goog.net.XhrIo.onReadyStateChangeEntryPoint_ (engine.js:46)
at goog.net.XhrIo.onReadyStateChange_ (engine.js:46)
- Followed by this third error: Stream is already broken.
engine.js:46 Uncaught Error: The stream is broken @2708513/0. Error: stream already broken. With input:
99,128,0,0,1,236,208,172,163,210,128,67,44,83,208,137,219,121,41,88,226,209,47,195,207,253,143,253,176,8,64,0,16,16,16,16,16,16,16,16,16,16
..................(a lot of these numbers).......
7,219,20,145,32,139,3,180,179,125,199,168,50,121,138,253,205,4,247,221,121,229,25,20,57,18,212,106,105,160,144,192,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,15,253,121,56,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,141,15,92,14,183,208,184,113,6,223,139,124,91,184,173,184,229,37,205,105,53,154,230,141,20,107,74,157,3,81,103,24,156,143,240,9,7,9,248,86,59engine.js:46)
at module$contents$grpc$web$GrpcWebStreamParser_GrpcWebStreamParser.parse (engine.js:46)
at goog.net.XhrIo.<anonymous> (engine.js:46)
at goog.net.XhrIo.goog.events.EventTarget.fireListeners (engine.js:46)
at Function.goog.events.EventTarget.dispatchEventInternal_ (engine.js:46)
at goog.net.XhrIo.goog.events.EventTarget.dispatchEvent (engine.js:46)
at goog.net.XhrIo.onReadyStateChangeHelper_ (engine.js:46)
at goog.net.XhrIo.onReadyStateChangeEntryPoint_ (engine.js:46)
at goog.net.XhrIo.onReadyStateChange_ (engine.js:46)
module$contents$grpc$web$GrpcWebStreamParser_Parser.error_ @ engine.js:46
module$contents$grpc$web$GrpcWebStreamParser_GrpcWebStreamParser.parse @ engine.js:46
(anonymous) @ engine.js:46
goog.events.EventTarget.fireListeners @ engine.js:46
goog.events.EventTarget.dispatchEventInternal_ @ engine.js:46
goog.events.EventTarget.dispatchEvent @ engine.js:46
goog.net.XhrIo.onReadyStateChangeHelper_ @ engine.js:46
goog.net.XhrIo.onReadyStateChangeEntryPoint_ @ engine.js:46
goog.net.XhrIo.onReadyStateChange_ @ engine.js:46
And then the third error keeps on appearing non stop.
I have tried to change enovy proxy config, with SSL, without SSL and I have the same issue.
I do a force reconnect to the stream using this piece of code, errors disappear and it works fine for a while but the errors reappear sooner or later.
Also, the streamObj.cancel() doesn't appear to do anything on the server side.
function getStream(streamObj, request) {
if (streamObj) {
streamObj.cannel();
}
streamObj = SomeServiceClient.getMyStream(request, {});
}
function myFuncThatUsesStream(parameters) {
var streamObj;
var request = new Mymessage();
request.setParam('value');
streamObj = getStream(streamObj, requestObj);
// do something with stream now
stream.on('data', ....
}
I tried connecting to the same grpc server directly (no proxy, no ssl) using a python client and I get this error in the stream and the client simply stops responding after that.
runtimeWarning: Unexpected end-group tag: Not all data was converted
I'm not sure what's wrong here, whether it's my client implementation issue, grpc-web issue, Envoy proxy or protobuf issue. If anyone can help out to figure this out, it'd be great! Thanks.
Can you share your .proto and your grpc server implementation?
For the 3 client side errors, the key is the first one. After the first one, the rest are expected - basically the parser got into an irrecoverable state after encountering an unrecognized frame byte. We need to find out where the byte came from.
If your python grpc client also fails, then the problem might be in your server but it's unclear from the information right now.
Hi @stanley-cheung, sorry for the late response. Here's the partial proto for the streaming rpc.
syntax = "proto3";
option java_multiple_files = true;
option java_package = "xyz.package_name";
option java_outer_classname = "AbcServer";
option objc_class_prefix = "HLW";
service Abc {
rpc Init (GenericRequest) returns (GenericResponse);
.
.
rpc Connect (Message) returns (stream ServerMessage);
.
.
.
}
message GenericRequest {
repeated Person person = 1;
Device device = 2;
string file = 3;
string type = 4;
string objectId = 5;
bytes scene = 6;
string previewId = 8;
}
message GenericResponse {
int32 status = 1;
string message = 2;
DeviceSettings settings = 3;
// Person person = 4;
repeated Person person = 8;
bool update = 5;
Device device = 6;
repeated Zone zones = 7;
string objectId = 9;
string objectName = 10;
}
message Phase {
string phaseId = 1;
bytes image = 2;
string location = 3;
string personId = 4;
bool enrolled = 5;
string name = 6;
string status = 7;
}
message Alert {
string sensorId = 1;
string recipientEmail = 2;
string title = 3;
string text = 4;
string zone = 5;
repeated string id = 7;
repeated string files = 6;
int64 time = 8;
bytes image = 9;
string sensorName = 10;
bytes scene = 11;
repeated string personId = 12;
repeated string imageData = 13;
string stringDate = 14;
string name = 15;
string alertId = 16;
repeated Phase phases = 17;
string imageLink = 18;
Type type = 19;
bool auth = 20;
string smsNumbers = 21;
string recipientSMS = 22;
string recipientVoice = 23;
Mode mode = 24;
string cpType = 25;
string deviceId = 26;
string objectId = 27;
bool oldAlert = 29;
repeated bytes phase = 30;
enum Mode {
AUTO = 0;
MANUAL = 1;
}
enum Type {
UNKNOWN = 0;
UNAUTH = 1;
AUTH = 2;
}
}
message Person {
bytes image = 1;
string personId = 2;
string imageLink = 3;
string uniqueCoreId = 4;
string name = 5;
bool authorized = 6;
Status status = 7;
enum Status {
UNAUTHORIZED = 0;
AUTHORIZED = 1;
}
string id = 8;
bool alert = 9;
int64 diff = 10;
string rekonId = 11;
int64 captureTime = 12;
string lastName = 13;
string class = 14;
repeated Role roles = 15;
string objectId = 16;
string phone = 19;
string username = 20;
string password = 21;
string email = 22;
bytes scene = 23;
int64 blur = 24;
double phaseWidth = 25;
double phaseHeight = 26;
double similarity = 27;
int32 numberOfPhases = 28;
int64 enrolledDate = 29;
EnrollmentType enrollmentType=30;
BoundingBox boundingBox=40;
enum EnrollmentType{
APP=0;
SENSOR=1;
}
}
message LivePreview {
int64 id = 1;
bytes image = 2;
string date = 3;
string device = 4;
}
message Message {
string from = 1;
string message = 2;
Alert alert = 3;
GenericResponse enrolled = 4;
MessageType messageType = 5;
LivePreview preview = 6;
string objectId = 7;
string objectName = 8;
bool dapt=9;
Person person=10;
enum MessageType {
TEXT = 0;
ALERT = 1;
ENROLLMENT = 3;
PREVIEW = 4;
DISMISS = 5;
}
}
message ServerMessage {
Message message = 1;
}
.
.
.
.
grpc server is implemented in Java, you would like to see the relevant streaming method I presume?
Hi all, this is the stripped server side implementation.
Server builder (we don't have any other issues with this):
server = ServerBuilder.forPort(options.port)
.addService(new Service1())
.addService(new Service2())
.useTransportSecurity(new File(options.certChainPem),
new File(options.serverKey))
.build();
When client is connected observer is added in the list of connected observers.
public void connect(Message message, StreamObserver<ServerMessage> responseObserver) {
previewObservers.add(responseObserver);
}
When server has some data prepared for the clients, data is sent to all observers.
for (StreamObserver observer : previewObservers){
observer.onNext(ServerMessage.newBuilder().setMessage(message).build());
}
Interesting is that on the client side, if window tab in browser is active, error will be delayed. When you move focus from the tab, error will kick really fast.
I get this error sometimes, generally a few seconds before the stream breaks. Could be unrelated as it's not too frequent.
message: "Failure: Invalid wire type"
messagePattern: "Failure: Invalid wire type"
reportErrorToServer: true
stack: "AssertionError: Failure: Invalid wire type↵ at new goog.asserts.AssertionError (https://my.domain.name/javascripts/engine.js:39:125631)↵ at Object.goog.asserts.fail (https://my.domain.name/javascripts/engine.js:39:126493)↵ at jspb.BinaryReader.nextField (https://my.domain.name/javascripts/engine.js:39:229649)↵ at Function.proto.ServerMessage.deserializeBinaryFromReader (https://my.domain.name/javascripts/engine.js:1:42445)↵ at module$contents$grpc$web$GrpcWebClientReadableStream_GrpcWebClientReadableStream.proto.ServerMessage.deserializeBinary [as responseDeserializeFn_] (https://my.domain.name/javascripts/engine.js:1:42342)↵ at goog.net.XhrIo.<anonymous> (https://my.domain.name/javascripts/engine.js:46:253438)↵ at goog.net.XhrIo.goog.events.EventTarget.fireListeners (https://my.domain.name/javascripts/engine.js:46:184226)↵ at Function.goog.events.EventTarget.dispatchEventInternal_ (https://my.domain.name/javascripts/engine.js:46:185451)↵ at goog.net.XhrIo.goog.events.EventTarget.dispatchEvent (https://my.domain.name/javascripts/engine.js:46:183058)↵ at goog.net.XhrIo.onReadyStateChangeHelper_ (https://my.domain.name/javascripts/engine.js:46:239555)"
__proto__: goog.debug.Error
constructor: ƒ (e,t)
name: "AssertionError"
__proto__: Error
Closing, issue was resolved. No problem found with grpc-web.
So what was the problem @verihelp-vaibhav ? I'm facing the same issue
Closing, issue was resolved. No problem found with grpc-web.
Getting a similar problem. I would appreciate it if you share your solution.
(For others) If I remember correctly, #561 led me to resolve this issue, and it has to do with gzip compression. You are still on your own though - there is no universal solution (yet).