Automated logout functionality not working, due to ajaxing property return true and ajaxStop event not triggering even though ajax req completed.

Created on 16 March 2023, over 1 year ago
Updated 30 November 2023, 7 months ago

Facing the automated logout functionality not working properly,

This functionality working fine with below setup:

  • Drupal version: 9.2.0
  • PHP version: 7.4
  • Automated logout module version: 8.x-1.0

Latest changes/upgrade in our project(dupal, php and contrib module. upgrade info):

  • Drupal version: 9.5.2
  • PHP version: 8.1.4
  • Automated logout module version: 8.x-1.4

Auto logout custom settings changes(Time out and padding) in admin panel:

  • Max Time out and Time out - 900 seconds
  • Time out Padding - 180 seconds.

Autologout flow:

With help of automated logout module which one trigger the 'autologoutGetTimeleft' function to fetch the remaining time from the server with help of Drupal.Ajax.

Once we getting an ajax call response which contains response[1].settings.time this field indicates the remaining time.


  • if this field (response[1].settings.time) > 0 means, again setup the timer with remaining time to call init function
  • Another hand, if response[1].settings.time < 0 means, we are showing the modal to indicate the user about 'session going to be expire' for 3 min or 180 seconds.

Here, I noticed critical/functionality breaking issue,
In our script(javascript) file, we have below code,

To display the "loading spinner":

jQuery(doucment).ajaxStart(function () {
  jQuery('#overlay').css('display', 'block');
});

To hide the "loading spinner":

jQuery(doucment).ajaxStop(function () {
  jQuery('#overlay').css('display', 'none');
});

while above Step-1 happening, we showing the loading spinner.

# Issue 1: Even though 'autologoutGetTimeleft' ajax finished, but ajaxStop function not triggering. so, due to 'ajaxStop' event not trigerring, still spinner appearing over the Autologout Timeout awareness Dialog/pop-up, like below

# Issue 2:
After first ajax call with either 'autologoutGetTimeleft' or 'autologoutRefresh' function depends on user active or not, On second time when either of these 'autologoutGetTimeleft' or 'autologoutRefresh', One of the ajax property called 'ajaxing' returning true. due to this one, whenever second time or third time either of the 'autologoutGetTimeleft' or 'autologoutRefresh' function invoking means, In that time getting "ajax.ajaxing = true", so autologout flow get cancelled. so, user login not able to auto-logout and always showing the spinner endlessly.

Below code:(autologout.js) from module for ajaxing return true (issue).

After calling any of the below function on second or third time, in that getting ajax.ajaxing as true always, due to this one autologout functionality get stopped.

// Autologout refresh
      Drupal.Ajax.prototype.autologoutRefresh = function (timerfunction) {
        var ajax = this;
        if (ajax.ajaxing) { // getting true on second/third time ajax call (critical issue) 
          return false;
        }
        ajax.options.success = function (response, status) {
          if (typeof response === 'string') {
            response = $.parseJSON(response);
          }
          if (typeof response[0].command === 'string' && response[0].command === 'alert') {
            // In the event of an error, we can assume the user has been logged out.
            window.location = localSettings.redirect_url;
          }
          t = setTimeout(timerfunction, localSettings.timeout);
          activity = false;
          // Wrap response data in timer markup to prevent detach of all behaviors.
          response[0].data = 
         '
' + response[0].data + '
'; // Let Drupal.ajax handle the JSON response. return ajax.success(response, status); }; try { $.ajax(ajax.options); } catch (e) { ajax.ajaxing = false; } }; // Autologout Get Remaining time Drupal.Ajax.prototype.autologoutGetTimeLeft = function (callback) { var ajax = this; if (ajax.ajaxing) { //getting true on second or thrid time ajax call (critical issue) return false; } ajax.options.submit = { uactive : activity }; ajax.options.success = function (response, status) { if (typeof response == 'string') { response = $.parseJSON(response); } if (typeof response[0].command === 'string' && response[0].command === 'alert') { // In the event of an error, we can assume user has been logged out. window.location = localSettings.redirect_url; } callback(response[1].settings.time); response[0].data = '
' + response[0].data + '
'; // Let Drupal.ajax handle the JSON response. return ajax.success(response, status); }; try { $.ajax(ajax.options); } catch (e) { ajax.ajaxing = false; } };

more about ajaxing property changes on drupal side Ajax related drupal side changes.

🐛 Bug report
Status

Fixed

Version

1.0

Component

Code

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.69.0 2024