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:
If user idle/inactive for 15 min (or) 900 seconds means,
Step 1: 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.
Step 2: Once we getting an ajax call response which contains response[1].settings.time this field indicates the remaining time.
Step 3:
- 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 2 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;
}
};
Note: more about ajaxing property changes on drupal side Ajax related drupal side changes.
| Comment | File | Size | Author |
|---|---|---|---|
| #8 | 3348394-8.patch | 1.73 KB | andersmosshall |
| #7 | autologout.js_.patch | 903 bytes | pravat231 |
Issue fork autologout-3348394
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
Selvam J commentedComment #3
Selvam J commentedComment #4
Selvam J commentedComment #5
avpadernoComment #6
Selvam J commentedHi @apadero/Team, Is any update for this issue?
Please, kindly share your thoughts.
Thanks!
Comment #7
pravat231 commentedInstead of calling the ajax.success directly, we should call with Promise which would solve the problem. This patch will solve your problem. patch created from this version 8.x-1.x
Comment #8
andersmosshall commentedAlso noted this issue. There is a change record for ajax.js in core here.
https://www.drupal.org/node/3293812
Effectivly the suggested solution is to store the original success callback, do your processing and then call the original callback again.
I created a patch doing just that.
Comment #9
avpadernoComment #12
deaom commentedApplied the patch from comment #8 and created a MR (so it easier to maintain). Tested the functionality which seems to work as expected. The tests are expected to fail because of a core migration issue #3192893: [META] Serialization issues in Migration tests, so see no reason this can be merged, but changing status to needs review, so somebody else can also test.
Comment #13
admirlju commentedThis fix causes a bug for me.
Specs:
After the 80s the dialog opens, and I click to extend the logged-in time. The dialog closes, and about 10-20s later the dialog shows up and immediately logs me out.
I'm checking out what is going on and for now, setting the status to needs work.
Comment #14
admirlju commentedSo it looks like my problem is not related to the fix in this issue. But is caused by #3301945: getRemainingTime treats logout_regardless_of_activity as always active. I'm moving this issue back to needs review.
Comment #15
admirlju commentedOk for some reason I'm still getting the bug mentioned in #13 and the fix from #14 was merged and the issue fork was rebased with that fix in it. So I have no clue why it's not working correctly again.
Comment #16
deaom commentedI re-tested again to see the behaviour and on D9.5 works fine (except for multiple dialogs adding on when you interact and extend the session by click on yes). But that issue should be resolved with #3214958: Autologout triggered in background tab, no indication in other open tabs. For things to move forward, I think this needs to be merged and then new issues can be opened and solved, so marking it as RTBC.
Comment #18
boshtian commentedComment #19
boshtian commentedComment #20
boshtian commentedComment #22
bhanu951 commented