[OpenLayers-Dev] ERRATUM - Race condition in WMSGetFeatureInfo

Gael Lafond G.Lafond at aims.gov.au
Thu Dec 9 20:41:59 EST 2010


I apology for the previous E-Mail (about the race condition issue), it
was a wrong conclusion lead by strange conditions.

I think there is still a Bug with handleResponse, but it related to
something else: the event listener only receive the responseText on the
last received response instead of an array or a concatenation of all of

--- Details ---

After half a day on this bug, a figure what was going out.

1st, all my tests demonstrated that JavaScript is single threaded (as
expected) and there is no race condition problem.

2nd, for some reason, my version of Firefox (v 3.6.12) is able to popup
multiple alerts when using Ajax requests. (see code sample bellow)

3rd, the problem with handleResponse, is that it concat the features,
but not the responseText. Since the event is only called once (after the
last received response), my event listener only receive one
responseText, the one of the last response.

I (temporary) fixed it by removing the IF in my extended class.
NOTE: Of corse, that will cause a lot of side effects. This is just to
illustrate the problem I had.

handleResponse: function(xy, request) {
  var doc = request.responseXML;
  if(!doc || !doc.documentElement) {
    doc = request.responseText;
  var features = this.format.read(doc);
  if (this.drillDown === false) {
    this.triggerGetFeatureInfo(request, xy, features);
  } else {
    this._features = (this._features || []).concat(features);
//  if (this._requestCount === this._numRequests) {
      this.triggerGetFeatureInfo(request, xy, this._features.concat()); 
      delete this._features;
      delete this._requestCount;
      delete this._numRequests;
//  }

--- Multiple popups in Firefox ---
NOTE: This code even works when the file (data.xml) do not exists (or
when run locally with a file:// URL).

function sendAjaxReq() {
  var xhr = new XMLHttpRequest(); 
  xhr.onreadystatechange  = function() { 
    if(xhr.readyState == 4) {
      // Alert shown twice, at the SAME time!
      alert("Code " + xhr.status);
  xhr.open("GET", "data.xml",  true); 

Gael Lafond
Australian Institute of Marine Science (AIMS)
Townsville MC
QLD 4810
Ph: +61 7 4753 4207
E-Mail: g.lafond at aims.gov.au

The information contained within this transmission is for the
use of the intended recipient only and may contain confidential
and/or legally privileged material and/or material the subject
of copyright and/or personal information and/or sensitive
information that is subject to the Privacy Act 1988. Any review,
re-transmission, disclosure, dissemination or other use of, or
taking of any action in reliance upon, this information by
persons or entities other than the intended recipient is
prohibited. If you have received this email in error please
notify the AIMS Privacy Officer on (07) 4753 4444 and delete
all copies of this transmission together with any attachments.

More information about the Dev mailing list