Merge "Fix an NPE on cancellation when connection is closed" into tm-dev