How can I get the id of a recently closed socket in Node without a session?

In node on closing a socket, i want to do some clean up in my database of a record containing that particular socket.

So i want something like:

socket.on('close', function(){
    removeRecordsWithSocket(lastSocketId);
});

The problem is I cant say something like lastSocketId = socket.connection.id inside the callback since the socket is already closed and socket is now null. I don't think I can set a global variable on the server since it's shared by all connections to the server and so will just have the value of the last connected socket. Assume also that I don't have a session object on the server. I just have the socket.

Can I use some other event (the connection event?) and some how namespace the connection to just this connection and access it on close? Or is there some better way? some node package?

Thanks!