We are having issuses using server.fetchSockets() in socket.io redis nodes. When a server call this function the others servers are throwing this exception:
C:\path\node_modules\socket.io-redis\dist\index.js:212
response = JSON.stringify({
^
TypeError: Converting circular structure to JSON
--> starting at object with constructor 'Pool'
| property 'config' -> object with constructor 'PoolConfig'
| property 'connectionConfig' -> object with constructor `ConnectionConfig'
--- property 'pool' closes the circle
at JSON.stringify (<anonymous>)
at RedisAdapter.onrequest (C:\Users\pach\Documents\trace gaming\new\node\node_modules\socket.io-redis\dist\index.js:212:33)
at processTicksAndRejections (node:internal/process/task_queues:94:5)
and the server that is calling the function gets a timeout.
Sending and receiving events are working fine.
socket.io 4.1.1 socket.io-redis 6.1.1
It seems like the object you want to convert is not meant to be converted to a JSON String or in other words:
JSON.stringify
does not know, when it has to stop converting already seen/converted objects.The drawing in the beginning of the socket-help explains the structure a bit.
Every client has a reference to the server, the server has references to all clients. So if you call
JSON.stringify()
on any of these objects the error occurs.This is just a rudimentary example how the references are set to help you understanding the error message:
How to avoid circular references:
You can add a replacer-function to
JSON.stringify(obj, replacer)
.Other questions that may be useful: