issue with js file loading time and Connection timeout
Hello everyone! A colleague of mine at $work discovered a strange issue with
his local tomcat in regards to loading times of js files and neither of us has
any idea why its happening the way it is. So he was developing some ajax /js
code to notify the users of our system in case the user got/ any new
notifications. And noticed long 20s loading time for his ajax script. When I
see it for myself I have(checkout his branch from git repo) no issues with load
times(on my computer the script is loading in 23 ms) His susspected that the
issue might be with connectionTimeout setting, because once he changed it from
20000 to 1000 the file was servered after 1s of wait time.He also noticed once
he added maxKeepAliveRequests attribute with the setting of 1 .the delay
dissapeared. completely, regardless of the connectionTimeout setting value.
here is the strange part. my connector does have the same ConnectionTimeout
setting value of 20000ms, NO maxKeepAliveRequests attribute
specified on the connector and the loading time has no delay. Any Idea why?
Below is my local connector
<Connector URIEncoding="UTF-8" connectionTimeout="20000" maxPostSize="-1"
port="8081" protocol="HTTP/1.1" redirectPort="8443"
useBodyEncodingForURI="true"/>
Both our machines have the own copy of tomcat 9.0.64 version which connect to
the same oracle 21 c db. Java is 1.8.202 on both machines. He is using Mac I
am on Windows 11
below is js file itself, althouth he tested the issue with much more simple
alert type js , the issue remained the same.
// Expose globally
window.startNotificationCheck = startNotificationCheck;
var baseUrl = window.location.origin + '/Education';
function startNotificationCheck(updateFunction) {
checkNotificationsAndUpdateCount(updateFunction);
}
async function checkNotificationsAndUpdateCount(updateCountFunction) {
let timerId; // Timer ID to control polling
let errorOccurred = false; // Local variable to track errors
async function check() {
try {
// const data = await checkNotifications();
let result = await makeRequest(
`${baseUrl}/protected/student-cabinet/Notifications/check/all`,
{ headers: { 'X-Check-Notifications': 'true' } }
);
// Unwrap the inner data so the update function gets counts directly
const counts = result.data ?? {};
// Call UI update with the counts object
updateCountFunction(counts);
errorOccurred = false;
} catch (error) {
errorOccurred = true;
clearTimeout(timerId);
// Check if it's an unauthorized error
if (error.status === 401 || error.message.includes('Unauthorized'))
{
//при завершении сессии
} else {
console.log('Notification check timer stopped due to an error:
' + error.message);
}
}
}
// Define the recursive polling function
function scheduleNextCheck() {
if (!errorOccurred) {
timerId = setTimeout(async () => {
await check();
scheduleNextCheck(); // Schedule the next check in 30 seconds
}, 30000);
}
}
// Start the polling loop
check().then(scheduleNextCheck);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]