Fix bug with hanging goroutines