If backend is closed, the operations on backend in compact goroutine will panic. So this PR waits for compact goroutine to exit before close backend. This fixes the TestWorkflow failure too.