2FA failing randomly

I’m having trouble with users complaining about 2fa codes failing randomly. Most of the time, 2fa works perfectly fine. All of a sudden, as some users login without trouble, others can’t. The next day, different users are affected. Sometimes it takes 8 attempts before some login successfully, as for others it fails continuously. This happens either with Google Authenticator or email.
Profile fields seem to be correctly updated. Webserver is IIS, database is SQL Server; profile field is of type text. No PHP errors getting logged.
I reset the user secret for an affected user; she scanned the new QR code from Google Authenticator successfully, but the second step kept failing.
It may be an volume related issue, as it seems to happen during training sessions, when multiple attending users are trying to login, but we’re talking about a dozen users at most.
I’m clueless about what took for. How can I debug this issue?

If it is a production server, enable Log error to file and check the log. If it is due to busy web server, you better enable the web server’s error and access log also, see if it could respond properly.

Thanks, I’ll do that.

An update on this issue: I’ve noticed that if I wait a few seconds and try the same code again, it works. If it fails, I just wait a little, click the input to make sure it’s selected and just press enter to resubmit the same code. Can take two or three tries.
It seems like the application takes some time to become aware of the new codes. This happens both with google authenticator and email codes.

Possibly due to time difference of the web server and mobile device? You may try to compare and sync your web server’s time with your mobile device’s.

Well, the server’s “Set time automatically” is on. The mobile devices get their time also from the celular network.
Could it be related to the server’s time zone?

You may try to increase Config("TWO_FACTOR_AUTHENTICATION_DISCREPANCY") (default is 1), e.g. in Global Code

Config("TWO_FACTOR_AUTHENTICATION_DISCREPANCY", 3); // Increase to 3

Apparently, that worked. Thanks a lot!