Hi Friso,
Any chance you could build your own mongo session management for jetty-9.4? We have totally re-architected sessions and made it much, much cleaner, clearer and easier to implement for different technologies? I really really recommend you go that way if you possibly can.
I'd be interested to know your motivation for rolling-your-own mongo session management? Always keen to know if there is some functionality that we should be providing in the standard jetty release that would be helpful to the greatest number of users ....
Looks to me like you've found some funnies in the mongo code around line 420: seems weird that we remove the attribute, and then call the http session value unbinding listener with a null value. Also undesirable that there is the side-effect of saving the session in doPutOrRemove: if more than 1 attribute had been removed from the session, the first iteration around would promptly write back in the other attributes! I would remove all of the attributes from the session, remembering their values and then call the http session unbinding listeners but forego calling sesion.save() at all.
For these kind of reasons, I strongly recommend basing your impl of jetty-9.4 instead.