Support Thread

Avatar Page Hangs Iis Hangs

Avatar Page Hangs Iis Hangs — APG vNext Guide

Avatar Page Hangs Iis Hangs — this archived support thread from the APG vNext community covers a reported issue and its resolution.

Troubleshooting This Issue

  1. Set customErrors mode="Off" in web.config to expose the full error and stack trace.
  2. Check Windows Event Viewer → Application log for ASP.NET exceptions.
  3. Review Admin Panel → Logs → Error Log for timestamped application errors.
  4. Restart the IIS Application Pool to clear stale state.
  5. Verify the database connection string and run any pending upgrade SQL scripts.

Related Resources

Avatar Page Causing IIS to Hang in APG vNext — Diagnosis and Fix

When the avatar upload or display page causes IIS worker processes to hang — characterised by the page loading indefinitely and eventually timing out — the root cause is usually one of three things: a synchronous image processing operation blocking the request thread, a corrupted avatar file caught in an infinite retry loop, or a missing GDI+ dependency on the server. This guide walks through each scenario with specific diagnostic steps and fixes.

Diagnosing the Hang

First, identify which IIS worker process is hanging and what it is waiting on:

-- Windows: open Task Manager → Details tab
-- Find w3wp.exe processes; note their PIDs

-- In an elevated command prompt:
procdump -ma [PID] C:\dumps\w3wp_avatar.dmp

-- Analyse with WinDbg or Visual Studio:
-- Load dump → Debug → Threads → look for threads
-- stuck in System.Drawing.Bitmap or GDI+ calls

Fix 1 — Replace System.Drawing with ImageSharp

APG vNext 4.x uses System.Drawing.Bitmap for image processing, which is a thin wrapper over GDI+ and is not safe for server-side use (Microsoft's own documentation warns against this). On constrained servers (limited GDI handles) it deadlocks. The fix is to switch to SixLabors.ImageSharp:

// Install via NuGet:
// Install-Package SixLabors.ImageSharp

using SixLabors.ImageSharp;
using SixLabors.ImageSharp.Processing;

public static void ResizeAvatar(string inputPath, string outputPath,
    int maxSize = 128)
{
    using var img = Image.Load(inputPath);
    img.Mutate(x => x.Resize(new ResizeOptions {
        Size = new Size(maxSize, maxSize),
        Mode = ResizeMode.Crop
    }));
    img.Save(outputPath);
}

ImageSharp is fully managed — no GDI handles, no COM threading model issues — and works correctly under IIS app pool identity.

Fix 2 — Async Avatar Processing with Background Queue

Move avatar processing off the request thread entirely using a background task queue. The user receives an immediate response, and the avatar is processed asynchronously:

// Queue avatar for async processing
AvatarProcessingQueue.Enqueue(new AvatarJob {
    TempPath    = uploadedTempPath,
    UserID      = currentUserID,
    RequestedAt = DateTime.UtcNow
});
// Return 202 Accepted immediately — avatar appears within seconds

Fix 3 — Corrupted Avatar File

A single corrupted uploaded avatar can cause the resize code to enter an infinite loop. Wrap all image operations in a timeout:

var cts = new CancellationTokenSource(TimeSpan.FromSeconds(10));
await Task.Run(() => ResizeAvatar(path, outputPath), cts.Token);

IIS Application Pool Tuning for Image Processing

The IIS application pool configuration has a direct impact on how well APG vNext handles concurrent avatar uploads. The default configuration is conservative and can be a bottleneck when multiple members upload avatars simultaneously:

<!-- web.config system.web processModel settings -->
<processModel
  maxWorkerThreads="50"
  maxIoThreads="50"
  minWorkerThreads="4"
  minIoThreads="4"
  requestQueueLimit="5000" />

<!-- In IIS Manager → Application Pools → [Your Pool] → Advanced Settings -->
<!-- Maximum Worker Processes: 1 (default, single process for session stability) -->
<!-- Disable Overlapped Recycle if avatar processing queue is in memory -->

Monitoring Thread Pool Exhaustion

When image processing hangs, it's often because all available worker threads are waiting for GDI+ operations. Monitor thread pool saturation with this PowerShell command:

# Check IIS worker process thread count (run while hang occurs):
Get-Process w3wp | ForEach-Object {
    $threads = $_.Threads.Count
    $handles = $_.HandleCount
    Write-Host "PID: $($_.Id)  Threads: $threads  Handles: $handles"
}

# A thread count above 100 suggests thread pool exhaustion
# A handle count growing continuously suggests GDI+ handle leak

Preventing Avatar Hangs Proactively

Set a Hard Timeout on the Avatar Upload Request

Ensure the avatar upload controller has a server-side timeout that terminates stuck image processing requests:

<!-- web.config: execution timeout for image processing requests -->
<location path="account/avatar">
  <system.web>
    <httpRuntime executionTimeout="15" maxRequestLength="2048" />
    <!-- 15 seconds is generous; legitimate avatar processing takes <2s -->
  </system.web>
</location>

Rate Limit Avatar Changes

Prevent members from flooding the avatar endpoint with rapid uploads (which can exhaust the thread pool faster in GDI+ environments):

<add key="APG.Avatar.MaxChangesPerDay" value="3" />
<add key="APG.Avatar.CooldownMinutes" value="10" />
<!-- Minimum 10 minutes between avatar changes -->

Long-Term Fix: Upgrade to APG vNext 5.x

The avatar hang issue is fundamentally a GDI+ architectural limitation that exists across all APG vNext 4.x versions. APG vNext 5.x replaced System.Drawing with ImageSharp and moved avatar processing to a background task queue, eliminating the hang entirely. If you are experiencing persistent avatar-related IIS hangs on 4.x, upgrading to 5.x is the definitive long-term resolution. The performance improvements in avatar processing alone justify the upgrade for communities with active member customisation.

Related Resources


Looking for more help? Browse the support forum or check the Knowledge Base.