Handle closed db exception during sync.

[Closes #5130]