Skip to content

ioredis throws an error that i cannot catch and make p3x-redis-server (p3x-redis-ui) crash #1310

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

Closed
p3x-robot opened this issue Mar 27, 2021 · 11 comments · Fixed by #1311
Closed
Labels

Comments

@p3x-robot
Copy link

hello!

what happening is that if a user configure a redis settings wrong, there is an error, that i cannot catch.
the error is like this:

[P3XRS] [PID: 018665]  Trace
    at parseType (/home/patrikx3/Projects/patrikx3/redis-ui-workspace/redis-ui-server/node_modules/redis-parser/lib/parser.js:302:17)
    at JavascriptRedisParser.execute (/home/patrikx3/Projects/patrikx3/redis-ui-workspace/redis-ui-server/node_modules/redis-parser/lib/parser.js:534:24)
    at Socket.<anonymous> (/home/patrikx3/Projects/patrikx3/redis-ui-workspace/redis-ui-server/node_modules/ioredis/built/DataHandler.js:25:20)
    at Socket.emit (events.js:315:20)
    at addChunk (internal/streams/readable.js:309:12)
    at readableAddChunk (internal/streams/readable.js:284:9)
    at Socket.Readable.push (internal/streams/readable.js:223:10)
    at TCP.onStreamRead (internal/stream_base_commons.js:188:23)
    at TCP.callbackTrampoline (internal/async_hooks.js:131:14)
[P3XRS] [PID: 018665]  3/27/2021, 6:19:33 AM unhandledRejection ReplyError: ERR SELECT is not allowed in cluster mode
    at parseError (/home/patrikx3/Projects/patrikx3/redis-ui-workspace/redis-ui-server/node_modules/redis-parser/lib/parser.js:179:12)
    at parseType (/home/patrikx3/Projects/patrikx3/redis-ui-workspace/redis-ui-server/node_modules/redis-parser/lib/parser.js:303:14) {
  command: { name: 'select', args: [ '1' ] }
} Promise {
  <rejected> ReplyError: ERR SELECT is not allowed in cluster mode
      at parseError (/home/patrikx3/Projects/patrikx3/redis-ui-workspace/redis-ui-server/node_modules/redis-parser/lib/parser.js:179:12)
      at parseType (/home/patrikx3/Projects/patrikx3/redis-ui-workspace/redis-ui-server/node_modules/redis-parser/lib/parser.js:303:14) {
    command: { name: 'select', args: [Array] }
  }
}

so if the user creates a setting for a non cluster that is actually a cluster this error happening and there is no way to catch, so my app crashes.
please let me know how i can disable this automatic select 1 command, when you are connecting to a clustered redis instance but with wrong connection, without enabling cluster mode.

@luin
Copy link
Collaborator

luin commented Mar 27, 2021

Hi @p3x-robot , I'm not sure where the select command was sent. Can you enable showFriendlyErrorStack and post the error stack here? Thanks!

@p3x-robot
Copy link
Author

redisConfig.showFriendlyErrorStack = true

it is happening, when i set the redisConfig.db = db => new Redis(redisConfig)

it happens, when a user wrong configuration sets (eg. the server is cluster, but the config is not in cluster mode)

[P3XRS] [PID: 024551]  3/27/2021, 7:05:54 AM unhandledRejection ReplyError: ERR SELECT is not allowed in cluster mode
    at Object.onceWrapper (events.js:421:28)
    at Socket.emit (events.js:327:22)
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1132:10)
    at TCPConnectWrap.callbackTrampoline (internal/async_hooks.js:131:14) {
  command: { name: 'select', args: [ '1' ] }
} Promise {
  <rejected> ReplyError: ERR SELECT is not allowed in cluster mode
      at Object.onceWrapper (events.js:421:28)
      at Socket.emit (events.js:327:22)
      at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1132:10)
      at TCPConnectWrap.callbackTrampoline (internal/async_hooks.js:131:14) {
    command: { name: 'select', args: [Array] }
  }
}

@p3x-robot
Copy link
Author

the problam is i cannot catch this error, uncoverable.

@luin
Copy link
Collaborator

luin commented Mar 27, 2021

Hmm, strange. The stack doesn't give any useful information. Is there a way I can reproduce the issue? I downloaded the electron package from https://github.com/patrikx3/redis-ui/releases but can't reproduce it. My steps:

  1. Setup a redis cluster with docker: docker run -e "IP=0.0.0.0" -p 7000-7005:7000-7005 grokzen/redis-cluster:latest
  2. Add a connection in P3X Redis UI. Port is 7000
  3. Click the refresh button on the upper right.

@p3x-robot
Copy link
Author

@luin :

set like this:
image

(make sure it is an error, disable cluster)

then connect to it, then on the home, select a database like 10. then refresh the browser, it will try to connect to database 10, then it crashes.
it is becuase we are using [redisconfig.db = 10 => new Redis(redisconfig) ]

@p3x-robot
Copy link
Author

ok, i solved it, with a different solution, but this errror exists... if you do not want to care about i can close it for you.

@luin
Copy link
Collaborator

luin commented Mar 27, 2021

I can finally reproduce this. How did you solve the issue? Regarding the solution, my current idea is to emit an error event and then ignore the failed select command (i.e. even if db: 10 is set, db 0 will still be connected). What do you think?

@p3x-robot
Copy link
Author

p3x-robot commented Mar 27, 2021

i disabled on the connection and when the gui reads the keys via scan, before, i call select ${db} and i silently hide the error if it is unable to set the database.

but what it is in the redisConfig.db is not usable right now and cannot be able to catch the error. i do no know which is the best solution, it is up to you.

@p3x-robot
Copy link
Author

yes i think it is a good solution to emit an error event, sure.

ioredis-robot pushed a commit that referenced this issue Mar 27, 2021
## [4.24.5](v4.24.4...v4.24.5) (2021-03-27)

### Bug Fixes

* select db in cluster mode causes unhandled errors ([#1311](#1311)) ([da3ec92](da3ec92)), closes [#1310](#1310)
@ioredis-robot
Copy link
Collaborator

🎉 This issue has been resolved in version 4.24.5 🎉

The release is available on:

Your semantic-release bot 📦🚀

@p3x-robot
Copy link
Author

thanks very much!

janus-dev87 added a commit to janus-dev87/ioredis-work that referenced this issue Mar 1, 2024
## [4.24.5](redis/ioredis@v4.24.4...v4.24.5) (2021-03-27)

### Bug Fixes

* select db in cluster mode causes unhandled errors ([#1311](redis/ioredis#1311)) ([da3ec92](redis/ioredis@da3ec92)), closes [#1310](redis/ioredis#1310)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants