Skip to content

Fix CLUSTER_NODES ipv6 address parsing #2269

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

Merged
merged 1 commit into from
Sep 19, 2022

Conversation

Pomkaize
Copy link
Contributor

@Pomkaize Pomkaize commented Sep 18, 2022

Description

Hi, I have found a bug with parsing ipv6 addresses from command CLUSTER NODES. This occurs because ipv6 address contains lots : symbols (2a02:6b8:c21:330d:0:1589:ebbe:b1a0:6379) so method indexOf parse just first part of ipv6 address, also afterward it produces null in port definition, finally socket can't be created and it throws an error:

(node:82513) UnhandledPromiseRejectionWarning: RangeError [ERR_SOCKET_BAD_PORT]: Port should be >= 0 and < 65536. Received NaN.
    at new NodeError (internal/errors.js:322:7)
    at validatePort (internal/validators.js:216:11)
    at lookupAndConnect (net.js:1013:5)
    at Socket.connect (net.js:989:5)
    at Object.connect (net.js:201:17)
    at RedisSocket._RedisSocket_createNetSocket (/Users/romanpoleguev/Dev/arcadia/classifieds/realty-frontend/node_modules/@redis/client/dist/lib/client/socket.js:196:21)
    at /Users/romanpoleguev/Dev/arcadia/classifieds/realty-frontend/node_modules/@redis/client/dist/lib/client/socket.js:163:101
    at new Promise (<anonymous>)
    at RedisSocket._RedisSocket_createSocket (/Users/romanpoleguev/Dev/arcadia/classifieds/realty-frontend/node_modules/@redis/client/dist/lib/client/socket.js:160:12)
    at RedisSocket._RedisSocket_connect (/Users/romanpoleguev/Dev/arcadia/classifieds/realty-frontend/node_modules/@redis/client/dist/lib/client/socket.js:134:150)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:82513) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 3)
(node:82513) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Before fix was made the line 'id 2a02:6b8:c21:330d:0:1589:ebbe:b1a0:6379@16379 master - 0 0 0 connected 0-549' has beed parsed as

{
  "id": "d1c81675fb0e70923207c250e558afce161dd1a9",
  "address": "2a02:6b8:c21:330d:0:1589:ebbe:b1a0:6379@16379",
  "host": "2a02",
  "port": null,
  "cport": 16379,
  "flags": [
    "master"
  ],
  "pingSent": 0,
  "pongRecv": 0,
  "configEpoch": 69,
  "linkState": "connected"
}

Now it works as intended.
Also test was written.


Checklist

  • Does npm test pass with this change (including linting)?
  • Is the new or changed code fully tested?
  • Is a documentation update included (if this change modifies existing APIs, or introduces new ones)?

@codecov-commenter
Copy link

codecov-commenter commented Sep 18, 2022

Codecov Report

Merging #2269 (8044561) into master (def9f16) will not change coverage.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master    #2269   +/-   ##
=======================================
  Coverage   95.85%   95.85%           
=======================================
  Files         433      433           
  Lines        4001     4001           
  Branches      451      451           
=======================================
  Hits         3835     3835           
  Misses        102      102           
  Partials       64       64           
Impacted Files Coverage Δ
packages/client/lib/commands/CLUSTER_NODES.ts 91.17% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@leibale
Copy link
Contributor

leibale commented Sep 19, 2022

@Pomkaize nice catch! Thanks!

@leibale leibale merged commit e1c0580 into redis:master Sep 19, 2022
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

Successfully merging this pull request may close these issues.

3 participants