changed close gate to sync.once