IBKR's servers undergo a nightly reset for maintenance purposes during which time applications will lose connection. This reset impacts all users, regardless of whether they are connecting via the TWS or the IB Gateway, although the duration is generally less than 1 minute and the user will be reconnected without having to log back in once the server comes back online.
Server reset times depend on where an account is hosted and may be found on our Current System Status page.