Fix NPE that may occur on container shutdown.

Issue: GCP-9405