I've been on a Russian train with a Canadian whose visa expired during the train ride (so just a couple of hours) as we crossed the border after midnight into Mongolia. Said passenger was marched off the train ("there is ... problem") and returned hours later with multiple fines and a black mark against their name.
Short answer: It's not worth the risk. BorderBorder guards are not known for their leniency and "I thought we could just wait" or "I didn't realise" is almost never an acceptable answer.