Bug 690170 - Part 2: clean up Resource and friends now we've found the culprit. r=philikon

This commit is contained in:
Richard Newman 2011-10-28 14:43:18 -07:00
parent 4391256da3
commit bdd9edb2af
2 changed files with 5 additions and 80 deletions

View File

@ -538,61 +538,21 @@ ChannelListener.prototype = {
// Clear the abort timer now that the channel is done.
this.abortTimer.clear();
/**
* Shim to help investigate Bug 672878.
* We seem to be seeing a situation in which onStopRequest is being called
* with a success code, but no mResponseHead yet set (a failure condition).
* One possibility, according to bzbarsky, is that the channel status and
* the status argument don't match up. This block will log that situation.
*
* Fetching channel.status should not throw, but if it does requestStatus
* will be NS_ERROR_UNEXPECTED, which will cause this method to report
* failure.
*/
let requestStatus = Cr.NS_ERROR_UNEXPECTED;
let statusSuccess = Components.isSuccessCode(status);
try {
// From nsIRequest.
requestStatus = channel.status;
this._log.trace("Request status is " + requestStatus);
} catch (ex) {
this._log.warn("Got exception " + Utils.exceptionStr(ex) +
" fetching channel.status.");
}
if (statusSuccess && (status != requestStatus)) {
this._log.error("Request status " + requestStatus +
" does not match status arg " + status);
try {
channel.responseStatus;
} catch (ex) {
this._log.error("... and we got " + Utils.exceptionStr(ex) +
" retrieving responseStatus.");
}
}
let requestStatusSuccess = Components.isSuccessCode(requestStatus);
let uri = channel && channel.URI && channel.URI.spec || "<unknown>";
this._log.trace("Channel for " + channel.requestMethod + " " + uri + ": " +
"isSuccessCode(" + status + ")? " + statusSuccess + ", " +
"isSuccessCode(" + requestStatus + ")? " +
requestStatusSuccess);
"isSuccessCode(" + status + ")? " + statusSuccess);
if (this._data == '') {
this._data = null;
}
// Check both the nsIRequest status and the status we were provided.
// If either is unsuccessful, don't take the success branch!
//
// Pass back the failure code and stop execution. Use Components.Exception()
// instead of Error() so the exception is QI-able and can be passed across
// XPCOM borders while preserving the status code.
if (!statusSuccess || !requestStatusSuccess) {
// Pick the code that caused us to fail.
let code = statusSuccess ? requestStatus : status;
let message = Components.Exception("", code).name;
let error = Components.Exception(message, code);
if (!statusSuccess) {
let message = Components.Exception("", status).name;
let error = Components.Exception(message, status);
this._onComplete(error, undefined, channel);
return;
}

View File

@ -412,42 +412,7 @@ RESTRequest.prototype = {
}
this.status = this.COMPLETED;
/**
* Shim to help investigate Bug 672878.
* We seem to be seeing a situation in which onStopRequest is being called
* with a success code, but no mResponseHead yet set (a failure condition).
* One possibility, according to bzbarsky, is that the channel status and
* the status argument don't match up. This block will log that situation.
*
* Fetching channel.status should not throw, but if it does requestStatus
* will be NS_ERROR_UNEXPECTED, which will cause this method to report
* failure.
*
* This code parallels nearly identical shimming in resource.js.
*/
let requestStatus = Cr.NS_ERROR_UNEXPECTED;
let statusSuccess = Components.isSuccessCode(statusCode);
try {
// From nsIRequest.
requestStatus = channel.status;
this._log.trace("Request status is " + requestStatus);
} catch (ex) {
this._log.warn("Got exception " + Utils.exceptionStr(ex) +
" fetching channel.status.");
}
if (statusSuccess && (statusCode != requestStatus)) {
this._log.error("Request status " + requestStatus +
" does not match status arg " + statusCode);
try {
channel.responseStatus;
} catch (ex) {
this._log.error("... and we got " + Utils.exceptionStr(ex) +
" retrieving responseStatus.");
}
}
let requestStatusSuccess = Components.isSuccessCode(requestStatus);
let uri = channel && channel.URI && channel.URI.spec || "<unknown>";
this._log.trace("Channel for " + channel.requestMethod + " " + uri +
" returned status code " + statusCode);
@ -455,7 +420,7 @@ RESTRequest.prototype = {
// Throw the failure code and stop execution. Use Components.Exception()
// instead of Error() so the exception is QI-able and can be passed across
// XPCOM borders while preserving the status code.
if (!statusSuccess || !requestStatusSuccess) {
if (!statusSuccess) {
let message = Components.Exception("", statusCode).name;
let error = Components.Exception(message, statusCode);
this.onComplete(error);