upstream changes from latest tornado (3.1.1)