audreyt / ethercalc

Node.js port of Multi-user SocialCalc
https://ethercalc.net
Other
2.96k stars 537 forks source link

Redis enable cluster mode #791

Open Edtcetera opened 1 year ago

Edtcetera commented 1 year ago

When I create a Redis node with the argument '--cluster-enabled yes' the ethercalc service begins to crash when a single user joins the spreadsheet with the following logs:

0|ethercalc  | join [log-fxtck74lslqx_formdata] [user-0.2646795842316232]

0|ethercalc  | TypeError: Cannot read property '0' of undefined

0|ethercalc  |     at /usr/local/lib/node_modules/ethercalc/main.js:826:28

0|ethercalc  |     at Command.callback (/usr/local/lib/node_modules/ethercalc/node_modules/redis/index.js:1144:17)

0|ethercalc  |     at RedisClient.return_error (/usr/local/lib/node_modules/ethercalc/node_modules/redis/index.js:571:25)

0|ethercalc  |     at ReplyParser.<anonymous> (/usr/local/lib/node_modules/ethercalc/node_modules/redis/index.js:317:18)

0|ethercalc  |     at ReplyParser.emit (node:events:376:20)

0|ethercalc  |     at ReplyParser.send_error (/usr/local/lib/node_modules/ethercalc/node_modules/redis/lib/parser/javascript.js:296:10)

0|ethercalc  |     at ReplyParser.execute (/usr/local/lib/node_modules/ethercalc/node_modules/redis/lib/parser/javascript.js:181:22)

0|ethercalc  |     at RedisClient.on_data (/usr/local/lib/node_modules/ethercalc/node_modules/redis/index.js:547:27)

0|ethercalc  |     at Socket.<anonymous> (/usr/local/lib/node_modules/ethercalc/node_modules/redis/index.js:102:14)

0|ethercalc  |     at Socket.emit (node:events:376:20)

0|ethercalc  |     at addChunk (node:internal/streams/readable:311:12)

0|ethercalc  |     at readableAddChunk (node:internal/streams/readable:286:9)

0|ethercalc  |     at Socket.Readable.push (node:internal/streams/readable:225:10)

0|ethercalc  |     at TCP.onStreamRead (node:internal/stream_base_commons:192:23)
PM2          | App [ethercalc:0] exited with code [1] via signal [SIGINT]

When cluster-enabled is default false, ethercalc multi-user support functions correctly

I am using Redis:7.0.5

Edtcetera commented 1 year ago

I will take a crack at this, from the looks of this I will need to upgrade node redis and follow their clustering guide as connecting to a redis cluster seems to be different: https://github.com/redis/node-redis/blob/master/docs/clustering.md

I assume the ethercalc connection to redis is done at db.ls : https://github.com/audreyt/ethercalc/blob/master/src/db.ls

Edtcetera commented 1 year ago

I've forked the project and managed to migrate the redis client package to the latest ioredis package which supports Redis Sentinel and Clusters: https://github.com/Edtcetera/ethercalc-ioredis/pull/1/commits/cf4565477126978c898947345401307b40c7cfe3

I will need to add more flags for Sentinel/Cluster setup, as well as support for Redis username