Topic doesn't have any active subscriptions

I have problem with Websockets


I’m using Adonis WS for communication with Angular frontend and HttpController for being notified by another program.
I’m using only one topic, and need to communicate with particular users (there are no “rooms” and client shouldn’t know about each other)
So the thing is that I need notify particular client WHEN I get POST with notify.

My WSController’s constructor:

    Log.notice(`New WS Connection ${}`)
    this.socket = socket
    this.request = request
    this.auth = auth
...some methods

async onNewpayment(txcount) {
    Log.notice(`User ${this.auth.user.uuid} made new payment request for ${txcount} BTC, getting new address`)
    const payment = await Blockchains.setNewPayment(, this.auth.user.uuid, txcount)
    this.socket.on('cancel', () => this.cancel())
    Blockchains.on('incoming', (payment) => {
      if (payment.userId === this.auth.user.uuid) {
        this.socket.emit('result', payment.resolved)
    this.socket.emit('payment', payment)

Blockchains is Provider and EventEmitter

it receives notifies from other HttpController and emits ‘incoming’ event with payment

But this.socket.emit(‘result’, payment.resolved) produces error - ‘Topic doesn’t have any active subscribers’). Client didn’t disconnected and still pinging the backend…

Please help :wink:

1 Like

I have been getting this question for while, but I am waiting for someone to share a repo with me, with the required code to reproduce this issue.

I tried and it worked for me. So please share a repo with the required code to reproduce this issue

I can’t just post whole idea of this program, but I’ll record private yt video where I’ll try reproduce the problem showing whole it’s path. I’m sorry it’s not Open Source and I don’t want to publish it yet

Not asking u to publish the entire code, you just have to share the minimum required code to reproduce the issue.

It’s hard for me to watch videos and then write code and then find the issue

OK I’ve resolved the problem

I forgot to disconnect the socket after transaction, so it worked only first time and created another connection for single client :slight_smile:

My first steps in websockets at all. Thanks for wishes for help, Sorry for bothering too :slight_smile:

The principle of a wesocket connection is to be kept open and exchange message not to be closed after each message. In adonis implementation, you can’t send message if no client is connected to a topic. You should wrap your call in a try catch first. A small example of your controller would help to improve this response :wink:

I my case I was unsubscribing from topic and then immediately closing connection
like so


and sometimes connection was closing before leaving topic