Python socketIO callback is lost: `Unknown callback received, ignoring.`

Question:

I have a Flask-SocketIO server that connects with a number of python-socketIO clients. I want to know which clients are online. To get to know this, I am sending a ping event from the server with a callback function to process the response.

The structure of the server code is as follows:

class Server:
    def ping(self):
        while True:
            self.socketio.emit(
                'ping', namespace='/some_namespace', room='some_room',
                callback=self.pong_response
            )

    def pong_response(self, client_id):
        # goal: updates the client's status as online in a database
        print(client_id)

In the client application, we have:

from socketio import ClientNamespace

class SocketClient(ClientNamespace):
    def on_ping(self) -> int:
        return <my_id>

Now, when I run the server and client application locally, this works fine: the client responds to the server and I can print the ID sent by the client app.

However, when the server app is deployed (in our case to an Azure App Service), the server logs print:

socketio.server - WARNING  - Unknown callback received, ignoring.

I have no clue why this works locally but not when deployed in Azure. Also, is this a good approach to update which client are online?


Possibly relevant details:

  • server is on Flask-SocketIO==5.1.1
  • clients are on python-socketio==5.5.0
  • Python 3.7
  • On the server, the ping/pong is running in a separate thread

Update:
It seems the message queue (RabbitMQ) is causing the issue. When defining our socketIO connection we use:

socketio = SocketIO(
    self.app,
    async_mode='gevent_uwsgi',
    message_queue=msg_queue,
)

It works when message_queue=None is put in. However, this obviously does not fix our issue when we want to run multiple server instances. I have yet to figure out why this doesn’t work and how I can fix it.

Asked By: Bart

||

Answers:

After doing more research and eventually posting this Github issue, the conclusion is that callbacks from multiple clients are not supported by python-socketio.

So since using callbacks is not an option to achieve this, I instead changed the code so that the clients send a ping to the server every N seconds (instead of the other way around). This way no callbacks are necessary.

Answered By: Bart