consumer not found Error

Hi, sometimes I’m getting “consumer not found” error I don’t know what is causing this error it shows in the console log in my publishing server while thousands of users are working.

thanks,

1 Like

You are calling a method on a Consumer that was already closed. That’s all.

1 Like

I’ve seen this error too with consumer.setPreferredLayers(), and when I catch the error and check consumer.closed and consumer.paused, they’re false. I also tried calling consumer.getStats() and consumer.pause() after catching, and those also throw an error, though consumer.close() still succeeds.

[EDIT: the following sentence is wrong]
This happens when the associated producer closes while consumer.setPreferredLayers() is in progress. Weird that it doesn’t make consumer.closed === true.

This is not true and I’ve confirmed it:

videoProducer.close();

try {
  await videoConsumer.setPreferredLayers({ spatialLayer: 1 });
} catch (error) {
  console.warn('-------- catch(): %s', error);
  console.warn('-------- 2 videoConsumer.closed:', videoConsumer.closed);
}

videoConsumer.closed === true in the catch block as expected. This is super tested.

No where in the docs it’s said that any mediasoup close() method throws if the entity is already closed. Nowhere.

Not true. Really.

you’re right, consumer.close() succeeding isn’t useful information here.

I investigated my issue further and you’re right, the issue I saw isn’t caused by the producer closing while setPreferredLayers() is happening. It’s caused by the producer closing in the middle of creating the consumer with transport.consume().

Here’s a toy way based off of mediasoup-demo through which I can reproduce locally the issue that I was seeing. Replace Room.ts lines 1576-1590 with

                setTimeout(() => producer.close(), 0);
                consumer = await transport.consume(
                        {
                                producerId      : producer.id,
                                rtpCapabilities : consumerPeer.data.rtpCapabilities,
                                paused          : true
                        });
                logger.error("HERE CREATE", producer.id, consumer.closed, producer.closed);
                try {
                  await consumer.setPreferredLayers({ spatialLayer: 0 });
                  logger.error("HERE SUCCESS", producer.id, consumer.closed, producer.closed);
                } catch (e) {
                  logger.error("HERE CAUGHT", producer.id, consumer.closed, producer.closed);
                  logger.error(e);
                  await new Promise(r => setTimeout(r, 2000));
                  logger.error("HERE WAIT", producer.id, consumer.closed, producer.closed);
                }
                await new Promise(r => setTimeout(r, 2000));
                process.exit(1);

and then enter the room with two Chrome windows. It doesn’t always produce the error, but I occasionally get a trace like this:

2021-01-28T11:26:25.160Z mediasoup-demo-server:ERROR:Room HERE CREATE ae789c9b-a7ba-4670-940f-1d169c34f64b false true
...
2021-01-28T11:26:25.161Z mediasoup-demo-server:ERROR:Room HERE CAUGHT ae789c9b-a7ba-4670-940f-1d169c34f64b false true
2021-01-28T11:26:25.162Z mediasoup-demo-server:ERROR:Room Error: Consumer not found
    at Channel._processMessage (/Users/t/code/mediasoup-demo/server/node_modules/mediasoup/lib/Channel.js:199:37)
    at Socket.<anonymous> (/Users/t/code/mediasoup-demo/server/node_modules/mediasoup/lib/Channel.js:61:34)
    at Socket.emit (node:events:376:20)
    at Socket.EventEmitter.emit (node:domain:470:12)
    at addChunk (node:internal/streams/readable:305:12)
    at readableAddChunk (node:internal/streams/readable:280:9)
    at Socket.Readable.push (node:internal/streams/readable:219:10)
    at Pipe.onStreamRead (node:internal/stream_base_commons:192:23)
...
2021-01-28T11:26:27.162Z mediasoup-demo-server:ERROR:Room HERE WAIT ae789c9b-a7ba-4670-940f-1d169c34f64b false true

anyway, your original answer from September is still the answer to this issue—the associated producer is closed, so the consumer is dead and you can’t use it. It’s still surprising to me that consumer.closed sometimes prints as false even after two seconds of sleeping.

Please log consumer.on('produceclose') after the consumer is created to see when it happens.

It should be true.

Ok, I see the problem.

  • When setPreferredLayers() succeeds, then immediately we get the ’ producerclose’ event in the Consumer so consumer.closed === true after that event.
  • However, when setPreferredLayers() fails due to Consumer not found, the ‘producerclose’ event never happens so consumer.closed === false forever.

I see the problem. We are receiving the producerclose event for this Consumer before event we create the Consumer in the Node layer, so it does not receive the producerclose event.

Fixed and released in mediasoup 3.6.32:

Thanks a lot @tomtseng!

2 Likes

thanks for investigating! I was pleasantly surprised that you responded so quickly and now have fixed the anomaly so quickly

Your code snippet above helped :slight_smile: