fix error: trying to open unclosed connection