keep session in sync

This PR is a lightweight version of https://github.com/owncloud/core/pull/9681. It will try to keep the session in sync and write a warn message to the log file.

@icewind1991 @bantu @DeepDiver1975 @karlitschek @craigpg