Fix #13103. Add .finish() method. Cherry picked from b6abb31df4d5be80dc13844d9988fb0c990ae5ae.