What does need to be closed on client disconnect?

Hey guys, I get this error after a while: [no more available ports [transport:udp, ip:’’, numAttempt:101] even though I close transports on disconnect.

socket.on('disconnect', () => {
                console.log('Client disconnected', socket.id);
                const producer = this.producers.get(socket.id);
                const producerTransport = this.transports.producer.get(socket.id);
                if (producer)
                if (producerTransport)
                socket.broadcast.emit('clientDisconnected', { socketId: socket.id });

So I wonder if I need to close any other transport. Do I have to close consumer too? I use single room logic where all clients consume each other.

Ports when connected:

mediasoup 630199            root   14u  IPv4 ..... 0t0  UDP *:10025
mediasoup 630199            root   15u  IPv4 ..... 0t0  TCP *:10025 (LISTEN)
mediasoup 630199            root   16u  IPv4 ..... 0t0  UDP *:10030
mediasoup 630199            root   17u  IPv4 ..... 0t0  TCP *:10021 (LISTEN)

After disconnect:

mediasoup 630199            root   16u  IPv4 ..... 0t0  UDP *:10030
mediasoup 630199            root   17u  IPv4 ..... 0t0  TCP *:10021 (LISTEN)

You need to close the transports you create in mediasoup side, that’s all. I don’t know if you are doing something wrong in your code, but the theory is easy: If you create transports associated to a “user” and the user disconnects, you must close the transports you created by calling close() on them. That’s all.

When I close consumer transport that was created for client that disconnected then ports are free but sometimes I get an error: Error: Consumer not found in mediasoup/lib/Channel.js:199:37. What does have to be done before I can close consumer transport?

I also have a set of remote clients for each client that I loop through and close all consumers with id of disconnected client.

                for (const [socketId, set] of this.consumerSets.entries()) {
                    for (const [remoteId, consumer] of set.entries()) {
                        if (remoteId === socket.id) {
                            console.log("Deleted consumer of", socketId, "for", remoteId);
                if (consumerTransport)

I don’t know what a “consumer transport” is. Anyway you are talking about “closing transports” then you show code that closes consumers. I don’t follow, sorry.

I just follow examples and there is consumer transport. It is created for client when they connect and want to consume all other clients. My previous message shows code that closes consumers.

This is a message from the worker process. Probably you are closing consumer after its producer has been closed (along with all associated consumers). Just close the consumer transport. There is no need to close consumers manually when the transport is closed.

Ok, I suggest following the documentation instead of examples.

Yes, you are right. Thanks a lot.