Skip to content
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

moleculer crash if ioredis can not change state to "ready" #1257

Closed
0x0a0d opened this issue Nov 14, 2023 · 1 comment
Closed

moleculer crash if ioredis can not change state to "ready" #1257

0x0a0d opened this issue Nov 14, 2023 · 1 comment

Comments

@0x0a0d
Copy link
Contributor

0x0a0d commented Nov 14, 2023

Today, I accidentally entered the wrong Redis server address, which was actually another TCP service address, resulting in the application crashing
After hours of debugging, I see that It was happen because on the Redis transporter class

clientSub.on("connect", () => {

and
clientPub.on("connect", () => {

"connect" event not tell the redis client is "ready", just emits when a connection is established to the Redis server.
@icebob you can try with this code

const net = require('net')
const { ServiceBroker } = require('moleculer')

const localhost = '127.0.0.1'
const server = net.createServer()
server.on('connection', socket => {
  socket.end()
})
server.listen(0, localhost, () => {
  const broker = new ServiceBroker({
    transporter: `redis://${localhost}:${server.address().port}}`
  })
  broker.start().then(() => {
    console.log('Broker started.')
  }).catch(err => {
    console.error(err)
  })
})

After a moment, it will crash with error
image

I found just 1 way to keep moleculer does not crash that is changing line 45,51 of redis transporter class to

// line 45
clientSub.on("ready", () => { // was: clientSub.on("connect", () => {
// line 51
clientPub.on("ready", () => { // was: clientPub.on("connect", () => {
@icebob
Copy link
Member

icebob commented Jan 13, 2024

Nice catch

@icebob icebob closed this as completed in d36368b Jan 13, 2024
icebob added a commit that referenced this issue Jan 13, 2024
change from 'connect' to 'ready' event in redis clients. Fixes #1257
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

No branches or pull requests

2 participants