Simultaneous AJAX submissions result in form cache not getting updated for the second submission.

First AJAX request enters with form_id: form-F33rMm15SpMLv373G_xn3hRopsteTfkhm70Wi1PceSw
New form is built with new form_id: form-JR1EXYiJjXD6F4YgT2Dkq_sd2oJcSQfr1g-9Ai8MDK4
Response contains

{
  "command": "update_build_id",
  "old": "form-F33rMm15SpMLv373G_xn3hRopsteTfkhm70Wi1PceSw",
  "new": "form-JR1EXYiJjXD6F4YgT2Dkq_sd2oJcSQfr1g-9Ai8MDK4"
} 

which updates form_build_id using update_build_id in ajax.js

update_build_id: function (ajax, response, status) {
  $('input[name="form_build_id"][value="' + response.old + '"]').val(response.new);
}

Second AJAX request enters with same original form_build_id as first form-F33rMm15SpMLv373G_xn3hRopsteTfkhm70Wi1PceSw
New form is built with form_id: form-CyMki8IJH0TDuqWVj3Hn0DMqrYvIoNyviLbKcJfosoc
Response contains

{
  "command": "update_build_id",
  "old": "form-F33rMm15SpMLv373G_xn3hRopsteTfkhm70Wi1PceSw",
  "new": "form-CyMki8IJH0TDuqWVj3Hn0DMqrYvIoNyviLbKcJfosoc"
} 

however as form_build_id was updated by first request, the input field is not found in update_build_id.

Proposed change is to update form_build_id without using value if only one form exists on the page.

update_build_id: function (ajax, response, status) {
  var build_ids = $('input[name="form_build_id"]');
  if (build_ids.length == 1) {
   $('input[name="form_build_id"]').val(response.new);
  } else {
    $('input[name="form_build_id"][value="' + response.old + '"]').val(response.new);
  }
},

or update the form_build_id without using value if one cannot be found with the value of response.old

update_build_id: function (ajax, response, status) {
  var old_build_id = $('input[name="form_build_id"][value="' + response.old + '"]');
  if (old_build_id.length == 0) {
    $('input[name="form_build_id"]').val(response.new);
  } else {
    $('input[name="form_build_id"][value="' + response.old + '"]').val(response.new);
  }
}

Repro steps:

  1. click two ajax buttons at the same time (the second button must be clicked before the first one finishes processing). refer to image 1
  2. search through the response of each ajax submission for "update_build_id" and copy that whole command somewhere for reference. refer to image 2
  3. compare two responses. they will have the same "old" build id. refer to image 3

alternatively, you can put a breakpoint at the update_build_id function in core/misc/ajax.js and inspect the response data.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Tyler_Rivard created an issue. See original summary.

Tyler_Rivard’s picture

This issue severely effects modules that modify the form like inline_entity_form.

Tyler_Rivard’s picture

cilefen’s picture

Status: Active » Needs review
Issue tags: +JavaScript

Please put code tags around the code samples in the issue summary.

The last submitted patch, 3: multipleAjaxCallsOption1-2871829-3.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 3: multipleAjaxCallsOption2-2871829-3.patch, failed testing.

sudhanshug’s picture

Issue summary: View changes

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

RaisinBranCrunch’s picture

I don't understand why the patches failed.

fatal: corrupt patch at line 21

What does that mean? The patches end with newline... they applied fine on my system...

I remade them, and I'm attaching them again.

RaisinBranCrunch’s picture

Status: Needs work » Needs review
FileSize
634 bytes
670 bytes

Trying something else after Googling some things...

Patch files are different sizes, is that a good sign? ...

The last submitted patch, 10: patch1a.patch, failed testing. View results

Status: Needs review » Needs work

The last submitted patch, 10: patch2a.patch, failed testing. View results

RaisinBranCrunch’s picture

Status: Needs work » Needs review
FileSize
1.04 KB
1.07 KB

Okay, patch1 and patch2 failed because they were edited with nano, which messes them up apparently. Patch1a and patch2a failed because I used 8.3.7 and not 8.4.x-dev... let's hope these ones work... they successfully apply to my 8.4.x-dev site.

joelpittet’s picture

Issue tags: +Novice, +Vienna2017

This may be tricky but could follow the reproduce steps and the code is easy to review.

Nice cleanup of the previously identified named function being removed, BTW;)

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

joshmiller’s picture

Issue tags: -Vienna2017 +Nashville2018

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
Issue tags: -JavaScript +JavaScript
FileSize
129 bytes

The Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

Version: 9.5.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.