Properly close the connection in permission checks and also flush create command to make sure that it's finished