timostamm / protobuf-ts

Protobuf and RPC for TypeScript
Apache License 2.0
1.1k stars 129 forks source link

RpcError: missing response body #454

Closed imotai closed 1 year ago

imotai commented 1 year ago

The error message

jest
  console.log
    doc meta smoke test error RpcError: missing response body
        at /media/jackwang/993f27f5-6c63-4a2f-ab72-06639127f882/opensource/db3/src/db3js/node_modules/@protobuf-ts/grpcweb-transport/build/commonjs/grpc-web-transport.js:142:23 {
      code: 'INTERNAL',
      meta: {},
      methodName: 'Broadcast',
      serviceName: 'db3_node_proto.StorageNode'
    }

      at Object.<anonymous> (src/lib/db3.test.ts:48:21)

The package.js

{
    "name": "db3js",
    "version": "0.2.1",
    "main": "./dist/index.js",
    "module": "./dist/esm/index.js",
    "type": "module",
    "scripts": {
        "build": "tsup --legacy-output --loader .wasm=file --minify",
        "test": "jest"
    },  
    "dependencies": {
        "@deliberative/crypto": "^0.6.18",
        "@ethersproject/keccak256": "^5.7.0",
        "@noble/secp256k1": "^1.7.0",
        "@protobuf-ts/grpcweb-transport": "^2.8.2",
        "@protobuf-ts/runtime": "^2.8.2",
        "@protobuf-ts/runtime-rpc": "^2.8.2",
        "@scure/bip39": "^1.1.0",
        "google-protobuf": "^3.21.2",
        "js-sha3": "^0.8.0",
        "react": "^18.2.0",
        "react-dom": "^18.2.0",
        "react-use": "^17.4.0",
        "secp256k1": "^4.0.3",
        "smart-buffer": "^4.2.0"
    },  
    "devDependencies": {
        "@babel/core": "^7.20.2",
        "@babel/plugin-proposal-decorators": "^7.20.7",
        "@babel/preset-env": "^7.20.2",
        "@babel/preset-typescript": "^7.18.6",
        "@protobuf-ts/plugin": "^2.8.2",
        "@protobuf-ts/protoc": "^2.8.2",
        "@rollup/plugin-commonjs": "^23.0.2",
        "@rollup/plugin-wasm": "^6.0.1",
        "@swc/core": "^1.3.19",
        "@types/google-protobuf": "^3.15.6",
        "@types/jest": "^29.2.3",
        "@types/react": "^18.0.24",
        "@types/react-dom": "^18.0.8",
        "@types/secp256k1": "^4.0.3",
        "babel-jest": "^29.3.1",
        "jest": "^29.3.1",
        "jest-environment-jsdom": "^29.3.1",
        "node-fetch": "^3.3.0",                                                                                                                                                                                                                  
        "rollup-plugin-wasm": "^3.0.0",
        "ts-jest": "^29.0.3",
        "ts-node": "^10.9.1",
        "tsdx": "^0.14.1",
        "tslint": "~6.1.0",
        "tsup": "^6.5.0",
        "typescript": "^4.6.4",
        "whatwg-fetch": "^3.6.2"
    }   
}
~                                  

The test file

import { describe, expect, test } from '@jest/globals'
import { DB3 } from './db3'
import { DocMetaManager, DocStore, DocIndex, DocKey, DocKeyType, genPrimaryKey, object2Buffer } from './doc_store'
import { sign, getATestStaticKeypair, getAddress } from './keys'
import { TextEncoder, TextDecoder } from 'util'
global.TextEncoder = TextEncoder
global.TextDecoder = TextDecoder
import 'whatwg-fetch'

describe('test db3js api', () => {
    async function getSign() {
        const [sk, public_key] = await getATestStaticKeypair()
        async function _sign(data: Uint8Array): Promise<[Uint8Array, Uint8Array]> {
            return [await sign(data, sk), public_key]
        }
        return _sign
    }   

    test("doc meta smoke test", async () => {
        try {

            const db3_instance = new DB3('http://127.0.0.1:26659')
            const _sign = await getSign()
            const doc_meta_mgr = new DocMetaManager(db3_instance)
            const my_transaction_meta = { 
                keys: [
                    {
                        name: 'address',
                        keyType: DocKeyType.STRING,
                    },
                    {
                        name: 'ts',
                        keyType: DocKeyType.NUMBER,
                    },
                ],
               ns: 'my_trx',
               docName: 'transaction',
            }
            const result = await doc_meta_mgr.create_doc_meta(my_transaction_meta, "test_transaction", _sign)
            await new Promise(r => setTimeout(r, 1000))
            const docs = await doc_meta_mgr.get_all_doc_metas("my_trx", _sign)
            expect(docs.length).toBe(1)
            expect(docs[0].doc_name).toBe("transaction")
            expect(docs[0].desc).toBe("test_transaction")
            expect(docs[0].index.ns).toBe("my_trx")
        } catch(error) {
            console.log("doc meta smoke test error", error)
            expect(1).toBe(0)
        }
    })  

...
jlm0 commented 1 year ago

@imotai were you able to resolve this? I see that you closed the issue. I'm having a similar error with the response body missing.

valentinbreiz commented 11 months ago

same error here using React Native and expo

The result of fetch after the GRPC request is sent is:

LOG {"_bodyBlob": {"_data": {"__collector": [Object], "blobId": "4fbc3a18-453d-4b9b-b058-8e38f5adb1e1", "offset": 0, "size": 332}}, "_bodyInit": {"_data": {"__collector": [Object], "blobId": "4fbc3a18-453d-4b9b-b058-8e38f5adb1e1", "offset": 0, "size": 332}}, "bodyUsed": false, "headers": {"map": {"content-type": "application/grpc-web-text+proto", "date": "Sat, 23 Dec 2023 21:01:36 GMT", "grpc-accept-encoding": "identity,deflate,gzip", "grpc-encoding": "identity", "server": "envoy", "transfer-encoding": "chunked", "x-envoy-upstream-service-time": "64"}}, "ok": true, "status": 200, "statusText": "", "type": "default", "url": "http://192.168.137.42:8080/user.User/SignIn"}

And in wireshark I can see that I have my content in the body...

"size": 332 but still [RpcError: missing response body]

jcready commented 11 months ago

This is a bug with react native: https://github.com/facebook/react-native/issues/37505

Their fetch implementation is non-compliant.

valentinbreiz commented 10 months ago

This is a bug with react native: facebook/react-native#37505

Their fetch implementation is non-compliant.

I indeed saw fetch is really weird on react native and made my GRPC client working using polyfill for stream and encoding: github.com/Honeybrain/Mobile