title: Web Service Call in JavaScript Causing White Screen of Death (WSOD) in Browser
body: <p>Here's the specs:</p>
  
  <ul>
  <li>ASP.NET 3.5 using ASP.NET AJAX</li>
  <li>AJAX Control Toolkit</li>
  <li>jQuery 1.3.2</li>
  <li>web services</li>
  <li>IIS6 on Windows Server 2003 SP1</li>
  <li>SP1 SQLServer 2005 SP3 Site is SSL</li>
  <li>Infragistics Web Components 2009 Vol. 2 (using non-Aikido controls), UltraWebGrid and Tree control are main ones used.</li>
  </ul>
  
  <p>Here's the problem:
  I'm getting the White Screen of Death (WSOD) in IE 7/8. Basically, I have a page that has a left pane that has an AJAXControl Toolkit Accordion control where each accordion panes content is an Infragistics Tree Control. The right pane is a <code>&lt;div&gt;</code> that has an <code>&lt;iframe&gt;</code> whose content is reloaded based on what's clicked in the left menu pane.</p>
  
  <p>In the <code>&lt;iframe&gt;</code>, a page with one or more UltraWebGrid controls loads up when you click on a menu item in the left pane. The grids all havea templated button column. When you click on the edit button of a grid row a popup window to edit the record is opened. This works fine for about ten times and then on the tenth time (sometimes earlier), the popup window opens with the correct URL in the address bar, but the page never loads. </p>
  
  <p>We have an application that uses one popup window for updating records. Most of the time when you click on the [Edit] button to edit a record, the popup window opens and loads the update page. However, after editing records for a while, all of a sudden the popup window will open, but it stays blank and just hangs. The URL is in the address bar.</p>
  
  <p>Loading up Fiddler I noticed that the request for the update page is never sent which leads me to believe it's some kind of lockup on the client-side. If I copy the same URL that's in the popup window into a new browser window, the page generally loads fine.</p>
  
  <p>Observations:
   - Since the request is never sent to the server, it's definitely something client-side or browser related.
   - Only appears to happen when there is some semblance of traffic on the site which is weird because this appears to be contained within client-side code
   - There is a web service being called in the background every few seconds checking if the user is logged on, but this doesn't cause the freeze.</p>
  
  <p>I'm really at a loss here. I've googled WSOD but not much seems to appear related to my specific WSOD. Any ideas?</p>
  
  <p><strong>What the problem really is</strong></p>
  
  <p>So turns out the memory leaks (although I've sealed up some on the client-side) are not the issue. The issue is web service calls being made on the client-side. There is one that checks if a user is logged on every 4 seconds (to synchronize with another window) and then there are web service calls to get user preferences for a popup window and grid state. From what I've read, the web services have to be asynchronous. I assumed by calling them from JavaScript with success/fail callbacks that they were asynchronous but they really aren't. They're asynchronous from the client-side/browser point of view, but from the server-side, the call to the web service is made and returns when it is completed holding up any other operations since there is a limited number of connections.</p>
  
  <p>So what is the easiest way to just make the web service methods asynchronous? Does the web service need to be converted to a WCF web service or can I use my existing ASP.NET web service call? </p>
  
  <p><strong>And for historical purposes, here's what I thought the problem was originally:</strong></p>
  
  <p>I wasn't able to reproduce this locally or on our testing servers. However, I got Fiddler to simulate modem speeds and all of sudden I can replicate the WSOD on my local PC. So it appears to be a slow or temporarily slow connection when opening a popup window that causes it to choke, at least in my test environment.</p>
  
  <p>I did another test running IE without add-ons, <code>iexplore.exe -extoff</code>, but end up with the same result. I also fixed an issue where the iframe on the page was being recreated everytime the URL for the iframe changed. Part of my logic was omitted. Now the iframe is only created once. After that only the <code>src</code> attribute is updated when I want to load new content... my goof. I noticed some lingering window references in JavaScript closures, so now those are explicitly set to null in the closures when I'm done with them.</p>
  
  <p>I've also done some memory leak investigation:
   - As far as I can tell I do not have any circular references in the DOM and JavaScript or the other leak patterns mentioned here, <a href="http://www.ibm.com/developerworks/web/library/wa-memleak/?S_TACT=105AGX52&amp;S_CMP=cn-a-wa" rel="nofollow noreferrer">http://www.ibm.com/developerworks/web/library/wa-memleak/?S_TACT=105AGX52&amp;S_CMP=cn-a-wa</a></p>
  
  <ul>
  <li><p>I've  added the Crockenator's purge code for IE memory leaks (see <a href="http://www.crockford.com/javascript/memory/leak.html" rel="nofollow noreferrer">http://www.crockford.com/javascript/memory/leak.html</a>):</p>
  
  <p>$(document).ready(function() {
      function purge(d) {
          var a = d.attributes, i, l, n;</p>
  
  <pre><code>    if (a) {
          l = a.length;
  
          for (i = 0; i &lt; l; i += 1) {
              if (a[i]) {
                  n = a[i].name;
  
                  if (typeof d[n] === 'function') {
                      d[n] = null;
                      purgeCount++;
                  }
              }
          }
      }
  
      a = d.childNodes;
  
      if (a) {
          l = a.length;
          for (i = 0; i &lt; l; i += 1) {
              purge(d.childNodes[i]);
          }
      }        
  }        
  
  $(window).unload(function() {
    purge(document.body);
    //alert("purge count: " + purgeCount);
  });
  </code></pre>
  
  <p>});</p></li>
  </ul>
  
  <p>None of my improvements have fixed the problem. in my local test scenario. Any ideas? Anyone? Anyone? Bueller?</p>
  
  <p><strong>Last Update</strong></p>
  
  <p>Thanks David for pointing out that it was session state causing the problems in the web services. <strong>"ASP.NET queues all requests to the same 'session'. So if the first request blocks for too long, it will hold up any other queued requests."</strong></p>
  
  <p>So what we ended up doing was try to minimize web services using session state but we also added the recommended settings by Microsoft for the number of connections, see <a href="http://msdn.microsoft.com/en-us/library/ff647786.aspx#scalenetchapt10_topic9" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/ff647786.aspx#scalenetchapt10_topic9</a></p>