Attempt to fix data loss during session end v2

Original: #433

Ok. I've removed platform-specific code.