SibSoft Ltd.
Development Services
software products
 RegisterRegister    SearchSearch   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
EZYWebhost - Cheap XUpload & XFileSharing 100% campatible hosting

AJAX upload progress bar

File sharing script
Race Conditions with XUPload

 
Post new topic   Reply to topic    SibSoft Ltd Forum Index -> XUpload
View previous topic :: View next topic  
Author Message
Silverado



Joined: 26 May 2008
Posts: 4

PostPosted: Jun 02, 2008 8:27 am    Post subject: Race Conditions with XUPload Reply with quote

If you have a pop-up that automatically closes and and outstanding XMLHttpRequest, XUPload will give javascript errors sometimes.

The scenario is this:

if the XMLHttpRequest is in the state to enter the jahDone Function and you hit stop upload and the pop-up closes, the req variable can go away and that is bad.

I have updated xstatus.js to not close the pop-up window (either with the the stop transfer button or the close button of the pop-window) until any pending XML requests have completed.

Tested in Firefox and IE7.

I also noticed that the var req, wasn't defined anywhere.

Add this code to the top somewhere in the xstatus.js code

Code:

// if we are going to close the pop-up
var windowClosing = false;
// not sure why this wasn't previously defined.
var req = null;
var wpTID;
// I want the close function of the pop-up to stop the upload transfer
window.onunload = ClosePopUp;

function ClosePopUp()
{
    StopUpload(false);
}

function WaitPopupClose()
{
    if (!req || !callInProgress(req))
    {
   popupClose();
   clearInterval(wpTID);
    }
}


and change the code in StopUpload

Code:

function StopUpload(no_close)
{
    var op;
    var agt=navigator.userAgent.toLowerCase();
    var is_opera = (agt.indexOf("opera") != -1);
    if(window.parent.frames['xupload']){op=window.parent;} else {op=window.opener;}
    if (navigator.appVersion.indexOf("Safari")>0)
    {
        op.location.reload( true );
    }
    else if (!document.all || is_opera)
    {
        window.stop();
        op.frames['xupload'].stop();
    }
    else
    {
        window.document.execCommand('Stop');
        op.frames['xupload'].document.execCommand('Stop');
    }
    if(no_close)return;
    // wait for any pending XML transactions to complete
    if (!windowClosing)
    {
       windowClosing = true;
 
       if (req && callInProgress(req))
       {
       wpTID = setInterval('WaitPopupClose()', 100);
       }
       else
        {
           popupClose();
       }
    }
}


And in the jahDone function
Code:

function jahDone(url)
{
    if (req.readyState == 4)
    {
   // if the window is about to close, don't start another request
   if (!windowClosing)
   {
           if (req.status == 200)
           {
               results = req.responseText;
               window.clearTimeout(timeoutId);
               try {eval(results);} catch(err) {timeoutId = window.setTimeout(function(){ jah(url); }, 1000 );}
           }
      else if(req.status == 500)
      {
         timeoutId = window.setTimeout(function(){ jah(url); }, 1000 );
      }
   }
    }
}
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    SibSoft Ltd Forum Index -> XUpload All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group