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

AssertionError: Failure: Type not convertible to Uint8Array. #73

Closed
marcoreni opened this issue Jul 27, 2018 · 7 comments
Closed

AssertionError: Failure: Type not convertible to Uint8Array. #73

marcoreni opened this issue Jul 27, 2018 · 7 comments

Comments

@marcoreni
Copy link

Hello,

I'm receiving the following error while closing a connection.

I'm still investigating the root cause, but I tried to debug this specific stack and it seems that https://github.com/google/protobuf/issues/1319#issuecomment-286542948 solves the issue

AssertionError: Failure: Type not convertible to Uint8Array.
    at new goog.asserts.AssertionError (/usr/src/shared/node_modules/google-protobuf/google-protobuf.js:98:603)
    at Object.goog.asserts.fail (/usr/src/shared/node_modules/google-protobuf/google-protobuf.js:100:89)
    at Object.jspb.utils.byteSourceToUint8Array (/usr/src/shared/node_modules/google-protobuf/google-protobuf.js:248:257)
    at jspb.BinaryDecoder.setBlock (/usr/src/shared/node_modules/google-protobuf/google-protobuf.js:314:264)
    at new jspb.BinaryDecoder (/usr/src/shared/node_modules/google-protobuf/google-protobuf.js:312:486)
    at Function.jspb.BinaryDecoder.alloc (/usr/src/shared/node_modules/google-protobuf/google-protobuf.js:313:207)
    at new jspb.BinaryReader (/usr/src/shared/node_modules/google-protobuf/google-protobuf.js:331:433)
    at Function.proto.pb.CloseResponse.deserializeBinary (/usr/src/shared/node_modules/node-nats-streaming/lib/pb/protocol_pb.js:2642:16)
    at Object.callback (/usr/src/shared/node_modules/node-nats-streaming/lib/stan.js:338:38)
    at Object.callback (/usr/src/shared/node_modules/nats/lib/nats.js:1474:26)
@aricart
Copy link
Member

aricart commented Jul 27, 2018

@marcoreni can you tell me the npm version of your build?

@marcoreni
Copy link
Author

@aricart I'm running 0.0.28 . If this has already been solved by more recent releases we can safely close this, sorry for the confusion.

@aricart
Copy link
Member

aricart commented Jul 27, 2018

Excellent!

@marcoreni
Copy link
Author

Hello @aricart , I upgraded node-nats-streaming to v0.0.41 but I'm still receiving the error in some cases.

I saw that in 08b648e new Buffer() became Buffer.from, but the Buffer => Array conversion is still .toByteArray() instead of Array.from as stated in the related issue.

Can you please check?

@aricart aricart reopened this Aug 8, 2018
@aricart
Copy link
Member

aricart commented Aug 8, 2018

hi @marcoreni - could you please add a current stack trace that matches the your current npm/master? - I take it that your exception is failing here:

var cr = proto.CloseResponse.deserializeBinary(Buffer.from(msgOrError, 'binary').toByteArray());

Also can you tell me:

  • if you are providing your own nats client or using the default provided by the stan library.
  • what are the options that you set on your client.
  • what payloads are you using
  • what node version are you using

Thanks,

/a

aricart added a commit that referenced this issue Aug 8, 2018
…ome protobuf users when deserializing a protobuf from a Buffer (AssertionError: Failure: Type not convertible to Uint8Array). The fix is exposed in https://github.com/google/protobuf/issues/1319#issuecomment-286542948.

The opt-in fix requires a new client property called `protobufFix` to be set to `true`.
@aricart
Copy link
Member

aricart commented Aug 8, 2018

Just doing a local test that simulates the serialization/deserialization:

      // create the protobuf object serialize it to buffer
      let cr = new proto.CloseResponse();
      cr.setError("foo");
      let bm = Buffer.from(cr.serializeBinary());

      // nats will decode the message into a binary string - simulate that
      let bs = bm.toString("binary");

      // this is the parsing that happens on the handler for the close request
      let bm2 = Buffer.from(bs, 'binary');
      let out = proto.CloseResponse.deserializeBinary(bm2.toByteArray());
      out.getError().should.be.equal("foo");

I don't reproduce any errors.

Because the error you are experiencing is a flapper, I am willing to try an opt-in fix where you set an option protobufFix to true on the client. The toByteArray() would change to:

Buffer.prototype.toByteArray = function() {
  return protobufFix? Array.from(this) : Array.prototype.slice.call(this, 0);
};

Can you please try to reproduce using the branch?

aricart added a commit that referenced this issue Aug 8, 2018
…ome protobuf users when deserializing a protobuf from a Buffer (AssertionError: Failure: Type not convertible to Uint8Array). The fix is exposed in https://github.com/google/protobuf/issues/1319#issuecomment-286542948.

The opt-in fix requires a new client property called `protobufFix` to be set to `true`.
aricart added a commit that referenced this issue Aug 8, 2018
…ome protobuf users when deserializing a protobuf from a Buffer (AssertionError: Failure: Type not convertible to Uint8Array). The fix is exposed in https://github.com/google/protobuf/issues/1319#issuecomment-286542948.

The opt-in fix requires a new client property called `protobufFix` to be set to `true`.
aricart added a commit that referenced this issue Aug 8, 2018
…ome protobuf users when deserializing a protobuf from a Buffer (AssertionError: Failure: Type not convertible to Uint8Array). The fix is exposed in https://github.com/google/protobuf/issues/1319#issuecomment-286542948.

The opt-in fix requires a new client property called `protobufFix` to be set to `true`.
aricart added a commit that referenced this issue Aug 8, 2018
…ome protobuf users when deserializing a protobuf from a Buffer (AssertionError: Failure: Type not convertible to Uint8Array). The fix is exposed in https://github.com/google/protobuf/issues/1319#issuecomment-286542948.

The opt-in fix requires a new client property called `protobufFix` to be set to `true`.
aricart added a commit that referenced this issue Aug 8, 2018
…ome protobuf users when deserializing a protobuf from a Buffer (AssertionError: Failure: Type not convertible to Uint8Array). The fix is exposed in https://github.com/google/protobuf/issues/1319#issuecomment-286542948.

The opt-in fix requires a new client property called `protobufFix` to be set to `true`.
aricart added a commit that referenced this issue Aug 8, 2018
…ome protobuf users when deserializing a protobuf from a Buffer (AssertionError: Failure: Type not convertible to Uint8Array). The fix is exposed in https://github.com/google/protobuf/issues/1319#issuecomment-286542948.

The opt-in fix requires a new client property called `protobufFix` to be set to `true`.
aricart added a commit that referenced this issue Aug 8, 2018
…ome protobuf users when deserializing a protobuf from a Buffer (AssertionError: Failure: Type not convertible to Uint8Array). The fix is exposed in https://github.com/google/protobuf/issues/1319#issuecomment-286542948.

The opt-in fix requires a new client property called `protobufFix` to be set to `true`.
@aricart aricart closed this as completed Oct 1, 2018
@aricart
Copy link
Member

aricart commented Mar 30, 2020

I have seen this problem,becouse i did not set the binaryType of my websocket object in js code.
the data from my service is decode into Blob object by default

ws = new WebSocket("ws://127.0.0.1:8080/ws");
ws.onopen = function(){
...
ws.binaryType = 'arraybuffer';
...
}

it is fixed when i add ws.binaryType = 'arraybuffer';
hope i can help anyone

Stan is a node library, there's no websocket support.

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

No branches or pull requests

2 participants