moleculerjs / moleculer

:rocket: Progressive microservices framework for Node.js
https://moleculer.services/
MIT License
6.12k stars 580 forks source link

no clean exit on shutdown, with disableBalancer: true #1167

Closed me23 closed 1 year ago

me23 commented 1 year ago

Prerequisites

Please answer the following questions for yourself before submitting an issue.

Current Behavior

Maybe it correspond to this issue: https://github.com/moleculerjs/moleculer-channels/issues/49

I start a service with amqp-transport (rabbitmq) and moleculer-channels listen to a given topic. If i start a client with( disableBalancer:true) which send to this channel and then exit afterwards, than i get this error message :

moleculer-channels-amqp-test/node_modules/moleculer/src/transporters/amqp.js:434
            .assertQueue(queue, this._getQueueOptions(PACKET_REQUEST, true))
             ^

TypeError: Cannot read properties of null (reading 'assertQueue')
    at AmqpTransporter.subscribeBalancedRequest (/home/me/public_html/moleculer-channels-amqp-test/node_modules/moleculer/src/transporters/amqp.js:434:5)
    at /home/me/public_html/moleculer-channels-amqp-test/node_modules/moleculer/src/transporters/base.js:269:14
    at Array.map (<anonymous>)
    at /home/me/public_html/moleculer-channels-amqp-test/node_modules/moleculer/src/transporters/base.js:268:37
    at Array.map (<anonymous>)
    at /home/me/public_html/moleculer-channels-amqp-test/node_modules/moleculer/src/transporters/base.js:262:14

If i change disableBalancer:false the error-message went away.

Expected Behavior

The client should exit without error message, even with disableBalancer:true

Failure Information

Steps to Reproduce

I've created a minimal-repo here: https://github.com/me23/moleculer-channels-amqp-test.git

  1. clone repo and change path to it

  2. if you don't have an Rabbitmq running on localhost you could start one with docker: docker-compose up

  3. start the service: node source/service.js

  4. start the client: node source/client.js

  5. you get the error

  6. start the client with disableBalancer:false: node source/clientOk.js

  7. you get no error message



### Context

Please provide any relevant information about your setup. This is important in case the issue is not reproducible except for under certain conditions.

* Moleculer version: 0.14.26
* NodeJS version: 17.9.0
* Operating System: Ubuntu 22.10
AndreMaz commented 1 year ago

This is not related to channels as I can repro the issue even without it. Here's a repro code

"use strict";

const { ServiceBroker } = require("moleculer");

// Create broker
const broker = new ServiceBroker({
  disableBalancer: true,
  transporter: "amqp://localhost:5672",
});

broker.start().then(async () => {
  // broker.repl();
  console.log("Broker started");

  // await broker.Promise.delay(1000); 

  await broker.stop();
});

Note: With added delay(1000) the issue disappears.

I also managed to repro the issue with amqplib ^0.8.0, ^0.9.0, ^0.10.0