Fix potential NPE in logs when closing the river
(cherry picked from commit b39764f)