thriftrw / thriftrw-node

A thrift binary encoding library using bufrw
MIT License
57 stars 25 forks source link

Unable to deserialize response from thriftrw-go #152

Closed Willyham closed 7 years ago

Willyham commented 7 years ago

Please see https://github.com/thriftrw/thriftrw-go/issues/321

This appears to be an issue with thriftrw-node, though given the test cases I've been able to find, I think the issue could be with me using the library incorrectly. Even if that is the case, some docs to clarify this would be good.

See this archive for a reproducible test case: https://github.com/thriftrw/thriftrw-go/files/1218543/issue.tar.gz

abhinav commented 7 years ago

@Willyham I'm not entirely sure if this is an issue with ThriftRW Node either. The corrupted payload I showed you was what Node saw before it was decoded by ThriftRW.

@kriskowal any ideas?

prashantv commented 7 years ago

@Willyham Thanks for the really detailed repro!

I've seen something similar before where the body is converted to a string, which modifies the buffer, and then thriftrw isn't able to decode it.

I looked into the documentation for request, and found this little nugget:

  • encoding - encoding to be used on setEncoding of response data. If null, the body is returned as a Buffer. Anything else (including the default value of undefined) will be passed as the encoding parameter to toString() (meaning this is effectively utf8 by default). (Note: if you expect binary data, you should set encoding: null.)

I tried this out, and set encoding: null in options, and the issue is fixed!

  const options = {
      url: 'http://localhost:8001',
      encoding: null,
      body: body.value,
      headers: {
        "Rpc-Caller": 'web',
        "Rpc-Encoding": "thrift",
        "Rpc-Service": "foo",
        "Context-TTL-MS": 5000,
        "Rpc-Procedure": "Foo::bar"
      }
  }
> node test.js
Result of small:
null <Buffer 00 00 00 00 00 00 00 7b>
Result of big:
null <Buffer 14 da db 63 ff b5 b7 52>