Use defer to close a connection