rethinkdb / rethinkdb-ts

RethinkDB TypeScript driver
Apache License 2.0
123 stars 17 forks source link

trouble with `waitForHealthy` #90

Closed GaikwadPratik closed 3 years ago

GaikwadPratik commented 3 years ago

Describe the bug A clear and concise description of what the bug is.

To Reproduce Steps to reproduce the behavior: Use rethink-error to reproduce. After cloning it, run nom run build && node dist/index.js

Expected behavior Query should be executed without any errors upon reconnection

Actual behavior I am getting below logs as output

➜  rethink-test npm run build && node dist/index.js

> rethink-test@1.0.0 build
> rm -rf dist/* && tsc

Database connection error received in handler, reinitializing changefeed once rethink is up
Reconnected to db localhost driver
/Users/pratikgaikwad/dev/hive/code/rethink-test/node_modules/rethinkdb-ts/lib/response/cursor.js:248
                throw new error_1.RethinkDBError(results[0], {
                      ^

RethinkDBError [ReqlOpFailedError]: cannot subscribe to table `UnknownDb.unknowTable`: primary replica for shard ["", +inf) not available in:
r.db("UnknownDb").table("unknowTable").changes({
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    includeInitial: true,
    ^^^^^^^^^^^^^^^^^^^^^
    squash: false
    ^^^^^^^^^^^^^
})
^^

    at Cursor.handleErrors (/Users/pratikgaikwad/dev/hive/code/rethink-test/node_modules/rethinkdb-ts/lib/response/cursor.js:248:23)
    at Cursor.resolve (/Users/pratikgaikwad/dev/hive/code/rethink-test/node_modules/rethinkdb-ts/lib/response/cursor.js:185:18)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async Proxy.<anonymous> (/Users/pratikgaikwad/dev/hive/code/rethink-test/node_modules/rethinkdb-ts/lib/query-builder/term-builder.js:79:29)
    at async main (/Users/pratikgaikwad/dev/hive/code/rethink-test/dist/index.js:58:24)
    at async Object.error (/Users/pratikgaikwad/dev/hive/code/rethink-test/dist/index.js:95:13) {
  msg: 'cannot subscribe to table `UnknownDb.unknowTable`: primary replica for shard ["", +inf) not available',
  _type: 17,
  cause: undefined,
  term: [
    152,
    [
      [ 15, [ [ 14, [Array] ], 'unknowTable' ] ]
    ],
    { include_initial: true, squash: false }
  ],
  backtrace: []
}

System info

atassis commented 3 years ago

So the query here tries to be executed onto the unexisting database and returning the proper error. Also, the connection to the database is working in this example, so see no bug in this code. Closing.

GaikwadPratik commented 3 years ago

@atassis,

The database does exists. I named them as UnknownDB and UnknownTable. That is bad on my part. I wasn't thinking clearly.

GaikwadPratik commented 3 years ago

@atassis I renamed database and table and here is correct stack trace. Can you please reopen the issue again?

➜  rethink-test git:(main) npm run build && node dist/index.js

> rethink-test@1.0.0 build
> rm -rf dist/* && tsc

Database connection error received in handler, reinitializing changefeed once rethink is up
Reconnected to db localhost driver
/Users/pratikgaikwad/dev/hive/code/rethink-test/node_modules/rethinkdb-ts/lib/response/cursor.js:248
                throw new error_1.RethinkDBError(results[0], {
                      ^

RethinkDBError [ReqlOpFailedError]: cannot subscribe to table `TestRethinkErrorDB.TestRethinkErrorTable`: primary replica for shard ["", +inf) not available in:
r.db("TestRethinkErrorDB").table("TestRethinkErrorTable").changes({
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    includeInitial: true,
    ^^^^^^^^^^^^^^^^^^^^^
    squash: false
    ^^^^^^^^^^^^^
})
^^

    at Cursor.handleErrors (/Users/pratikgaikwad/dev/hive/code/rethink-test/node_modules/rethinkdb-ts/lib/response/cursor.js:248:23)
    at Cursor.resolve (/Users/pratikgaikwad/dev/hive/code/rethink-test/node_modules/rethinkdb-ts/lib/response/cursor.js:185:18)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async Proxy.<anonymous> (/Users/pratikgaikwad/dev/hive/code/rethink-test/node_modules/rethinkdb-ts/lib/query-builder/term-builder.js:79:29)
    at async main (/Users/pratikgaikwad/dev/hive/code/rethink-test/dist/index.js:58:24)
    at async Object.error (/Users/pratikgaikwad/dev/hive/code/rethink-test/dist/index.js:95:13) {
  msg: 'cannot subscribe to table `TestRethinkErrorDB.TestRethinkErrorTable`: primary replica for shard ["", +inf) not available',
  _type: 17,
  cause: undefined,
  term: [
    152,
    [
      [ 15, [ [ 14, [Array] ], 'TestRethinkErrorTable' ] ]
    ],
    { include_initial: true, squash: false }
  ],
  backtrace: []
}
atassis commented 3 years ago

Created db and table image

GaikwadPratik commented 3 years ago

Please pull up the git repo one more time. I updated dbname and tablename in the source code. And the stack trace after renaming is above

atassis commented 3 years ago

Cannot receive an error locally, some problems on your test stand, or missing more info. But think its a first case, this error shows when rethinkdb is busy with smth

GaikwadPratik commented 3 years ago

What more info do you need? So I should try by waiting more than 1 sec?

atassis commented 3 years ago

how to reproduce an error from scratch Which tables to create, etc

GaikwadPratik commented 3 years ago

I used below queries to create database, and table in web explorer:

r.dbCreate("TestRethinkErrorDB");
r.db("TestRethinkErrorDB")
  .tableCreate("TestRethinkErrorTable", { primaryReplicaTag: "hio_config", replicas: { "hio_config": 1 } });

the tag hio_config is embedded in db server that I'm working with. In essence this should be replicable with default tag as well.

So can you please reopen the bug so we can track it?

GaikwadPratik commented 3 years ago

Steps to reproduce:

  1. Make sure rethinkdb is running as service(in my case using systemd on ubuntu server)
  2. create db using r.dbCreate("TestRethinkErrorDB");
  3. create table using r.db("TestRethinkErrorDB").tableCreate("TestRethinkErrorTable")
  4. Clone rethinkdb-error repo from the link above
  5. install npm packages and run rpm run build && node dist/index.js in rethinkdb-error directory
  6. Once the node code is running, restart rethinkdb service(in my case, systemctl restart rethinkdb).
  7. Watch the node terminal from step 5 above
GaikwadPratik commented 3 years ago

@atassis ,

Can you please re-open this bug? or I can create a new one with all the information, if you prefer it that way