Get DDPConnection by connectionId and close it

Someone knows how to get the current DDP Connection on the server by a given connectionId? And if so, is it possible to force-close the connection from the server env?

I just checked, if you know the connectionId you can call the following on the server


and it will close the connection, but the client will simply reconnect. I have not found out how to prevent that.

Ok, I found a nifty workaround by using the livedata framework. Instead of closing the connection server-side, we send a message to the the connection (client) and have the client disconnect. On the client we need to overwrite the connection._livedata_error function

  console.log(`onReconnect ${connection._lastSessionId}`);
  // save original function
  const livedata_error = connection._livedata_error;
  // overwrite handler
  connection._livedata_error = function(msg) {
    // does this error msg contain disconnect: true
    if(msg && msg.disconnect && msg.disconnect === true) {
    } else {
      // call original function

With this patch in place we can use the following on the server

Meteor.default_server.sessions[connectionId].send({msg:"error",disconnect: true})