Opened 13 years ago

Closed 12 years ago

#2684 closed defect (fixed)

callbcak function is called twice if a bind arror happens

Reported by: zhaotq@… Owned by: alex
Priority: high Milestone: 1.0
Component: IO Version: 0.4.2
Keywords: Cc: zhaotq@…
Blocked By: Blocking:

Description

The problem is in dojo.io.XMLHTTPTransport.bind. The following code starts from line 610.

		if(kwArgs.method.toLowerCase() == "post"){
			// FIXME: need to hack in more flexible Content-Type setting here!
			if (!kwArgs.user) {
				http.open("POST", url, async);
			}else{
        http.open("POST", url, async, kwArgs.user, kwArgs.password);
			}
			setHeaders(http, kwArgs);
			http.setRequestHeader("Content-Type", kwArgs.multipart ? ("multipart/form-data; boundary=" + this.multipartBoundary) : 
				(kwArgs.contentType || "application/x-www-form-urlencoded"));
			try{
				http.send(query);
			}catch(e){
				if(typeof http.abort == "function"){
					http.abort();
				}
				doLoad(kwArgs, {status: 404}, url, query, useCache);
			}
		}else{
			var tmpUrl = url;
			if(query != "") {
				tmpUrl += (tmpUrl.indexOf("?") > -1 ? "&" : "?") + query;
			}
			if(preventCache) {
				tmpUrl += (dojo.string.endsWithAny(tmpUrl, "?", "&")
					? "" : (tmpUrl.indexOf("?") > -1 ? "&" : "?")) + "dojo.preventCache=" + new Date().valueOf();
			}
			if (!kwArgs.user) {
				http.open(kwArgs.method.toUpperCase(), tmpUrl, async);
			}else{
				http.open(kwArgs.method.toUpperCase(), tmpUrl, async, kwArgs.user, kwArgs.password);
			}
			setHeaders(http, kwArgs);
			try {
				http.send(null);
			}catch(e)	{
				if(typeof http.abort == "function"){
					http.abort();
				}
				doLoad(kwArgs, {status: 404}, url, query, useCache);
			}
		}

Before the code, the inFlightTimer is set up. When the http.send throw an exception, the doLoad is called, but the inFlightTimer is not cancelled. So, the callback is called twice, one is in the catch block, on is from the inFlightTimer.

Proposed change:

in the catch block before calling the doLoad:

if (async) clearTimeout(this.inFlightTimer);

Change History (1)

comment:1 Changed 12 years ago by James Burke

Milestone: 1.0
Resolution: fixed
Status: newclosed

This should be fixed in 1.0: the send call is wrapped in a try/catch, and the deferred.cancel is called if there is an error. In this case, the inflight checks will do nothing more, just remove it from the inflight queue.

Note: See TracTickets for help on using tickets.