Flush and shutdown agents in the event of an error.