Not sure about Shanghai, but in most countries there are (generous) time limits associated with fares, measured from first entry. Obviously this isn't enforced "in flight", but the gate will not let you out when you try to leave and you'll need to explain to staff why you've just spent 4 hours traveling one stop -- since odds are you actually went somewhere else and jumped the turnstile both ways.
I don't think there is a limit in Shanghai. A few years back there was a heat wave and the subway stations were full of people who just came to hang out where there was air conditioning.