Correctly handle invalid cookies

Fixes https://github.com/tornadoweb/tornado/issues/633