https://github.com/mperham/sidekiq
Revision a8ed20aef7bbb1ff35aa1a62ca6914f09d73bddf authored by John on 17 March 2022, 23:13:07 UTC, committed by GitHub on 17 March 2022, 23:13:07 UTC
Related to: https://github.com/mperham/sidekiq/pull/5230

### Bug #1: Multiple event listeners are added to elements

When adding event listeners to elements, Javascript will generally prevent duplicating the listener if the callback function is named. Anonymous functions aren't tracked the same way. Javascript will continue to add an event listener every time the polling happens. This commit names those functions where the listeners are added to elements outside of the "page" `div`.

The duplicate event listeners caused some odd behavior:

1. Clicking in the "Stop Polling" caused a single GET call to the server for each event listener on the element. This will be problematic if someone leaves the polling on for an extended period of time.
2. It would some times cause the "Stop Polling" functionality to not stop polling.

#### How to duplicate:

1. Open the page inspector from the developer tools of your browser.
2. Click on the "event" button next to the "Live Poll" button in the inspector. You'll see that there's only one event listener.
3. After the page does a poll, click on it again and you'll now see two event listeners with the same function.
4. Click on the stop polling button
5. Look at your server logs and you'll see a single request per event listener

### Bug #2: Ghost interval continues polling after clicking "Stop Polling"

Every time the `addListeners` function was called, it would call the `scheduleLivePoll()` function and setup a new `setTimeout`. Thus, when you clicked on the "Stop Polling" button, it would continue to poll because of a stray `setTimeout`. The only way to stop the polling was to refresh. This commit prevents the function from running if a timeout already exists.

#### How to duplicate:

1. All the UI to poll for 30 seconds
2. Clear your server logs
3. Click on "Stop Polling"
4. Watch your server logs and you'll see the same polling request continue to come in every five or so seconds.
1 parent b83c8e3
History
Tip revision: a8ed20aef7bbb1ff35aa1a62ca6914f09d73bddf authored by John on 17 March 2022, 23:13:07 UTC
Prevent stray polling interval from running and prevent duplicate event listeners (#5247)
Tip revision: a8ed20a
File Mode Size
.github
bin
examples
lib
myapp
test
web
.gitignore -rw-r--r-- 175 bytes
.standard.yml -rw-r--r-- 311 bytes
3.0-Upgrade.md -rw-r--r-- 3.0 KB
4.0-Upgrade.md -rw-r--r-- 2.0 KB
5.0-Upgrade.md -rw-r--r-- 2.5 KB
6.0-Upgrade.md -rw-r--r-- 2.9 KB
COMM-LICENSE.txt -rw-r--r-- 18.4 KB
Changes.md -rw-r--r-- 62.0 KB
Ent-2.0-Upgrade.md -rw-r--r-- 1.3 KB
Ent-Changes.md -rw-r--r-- 9.3 KB
Gemfile -rw-r--r-- 479 bytes
Gemfile.lock -rw-r--r-- 5.6 KB
LICENSE -rw-r--r-- 379 bytes
Pro-2.0-Upgrade.md -rw-r--r-- 4.4 KB
Pro-3.0-Upgrade.md -rw-r--r-- 1.3 KB
Pro-4.0-Upgrade.md -rw-r--r-- 1013 bytes
Pro-5.0-Upgrade.md -rw-r--r-- 628 bytes
Pro-Changes.md -rw-r--r-- 23.1 KB
README.md -rw-r--r-- 3.8 KB
Rakefile -rw-r--r-- 210 bytes
code_of_conduct.md -rw-r--r-- 2.3 KB
sidekiq.gemspec -rw-r--r-- 1.1 KB

README.md

back to top