Fixed #21255 -- Closed connections after management command ran

Thanks kabakov.as@gmail.com for the report, and Aymeric Augustin,
Simon Charette for the reviews.