GenerateSetupCode starts throwing GDI+ errors after a random period
See original GitHub issueHi, Thanks for writing an maintaining this! It does exactly what we need, except when it doesn’t.
We’re using this in a web app for 2FA. It runs fine for a random time period, but then starts throwing GDI+ errors for all calls to GenerateSetupCode. The first time, it only ran for about an hour with low volume. The second time it ran for 3 days with periods of high volume (5000 calls in a minute). The only thing that solves the problem is to reset the site in IIS.
I’ve watched TaskManager when generating the codes. The memory usage jumps while it’s processing, but then drops back down, so doesn’t seem like a memory leak.
Here’s the code we’re using (the real code only makes one call, of course, but this is what I’ve been testing with):
int qrCodeCount = 100;
for (int i = 0; i < qrCodeCount; i++)
{
string key = Guid.NewGuid().ToString().Replace("-", "").Substring(0, 10);
TwoFactorAuthenticator tfa = new TwoFactorAuthenticator();
SetupCode setupInfo = tfa.GenerateSetupCode("Test Portal", "SAMPLE" + key, key, false, 3);
if (setupInfo != null)
{
System.Web.UI.WebControls.Image img = new System.Web.UI.WebControls.Image();
img.ImageUrl = setupInfo.QrCodeSetupImageUrl;
//lblManualSetupCode.Text = setupInfo.ManualEntryKey;
phQRCodes.Controls.Add(img);
}
}
And the exception:
System.Runtime.InteropServices.ExternalException (0x80004005): A generic error occurred in GDI+.
at System.Drawing.Image.Save(Stream stream, ImageCodecInfo encoder, EncoderParameters encoderParams)
at Google.Authenticator.TwoFactorAuthenticator.GenerateQrCodeUrl(Int32 qrPixelsPerModule, String provisionUrl)
at Google.Authenticator.TwoFactorAuthenticator.GenerateSetupCode(String issuer, String accountTitleNoSpaces, Byte[] accountSecretKey, Int32 qrPixelsPerModule, Boolean generateQrCode)
at TopLineGroup.Web.Admin_OtherSiteMaintenance.lbTestMFAQRCodes_Click(Object sender, EventArgs e) in E:\...\OtherSiteMaintenance.aspx.cs:line 207
Issue Analytics
- State:
- Created a year ago
- Comments:8
Top GitHub Comments
So far so good with the beta.
I ran it manually on Friday and this morning with 100 codes every hour or so. And today I set it up to automatically refresh every 10 seconds, and I’m running it simultaneously in 15 tabs over 3 browsers with no problems.
How close it the beta to release? I’d like to try it in our live site, but if there are other known issues…
I get pretty much the same thing. Generating blocks of 100 at a time have no problem. It just randomly stops working at some point.
I have it running with the beta in a test environment now. I’ll periodically generate 100 or so and see if it breaks.