Skip to content

Commit

Permalink
Ensure existing timer is cleared before creating a new one
Browse files Browse the repository at this point in the history
We have seen some unexpected network requests for logs in error cases,
e.g. pod not ready, but have not been able to reliably reproduce them.

Ensure we clear any existing timer before starting a new one to ensure
we're not left with any remaining unaccounted for timers when navigating
away from the logs tab.

Also change existing use of `clearInterval` to `clearTimeout` for clarity.
Both use the same pool of ids and so are interchangeable, but we should be
consistent to avoid confusion.
  • Loading branch information
AlanGreene authored and tekton-robot committed Dec 2, 2021
1 parent a1f2f4a commit a51903f
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/components/src/components/Log/Log.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export class LogContainer extends Component {

componentWillUnmount() {
window.removeEventListener('scroll', this.handleLogScroll, true);
clearInterval(this.timer);
clearTimeout(this.timer);
this.cancelled = true;
}

Expand Down Expand Up @@ -370,6 +370,7 @@ export class LogContainer extends Component {
logs: logs ? logs.split('\n') : undefined
});
if (continuePolling) {
clearTimeout(this.timer);
this.timer = setTimeout(this.loadLog, pollingInterval);
}
}
Expand All @@ -385,6 +386,7 @@ export class LogContainer extends Component {
]
});
if (continuePolling) {
clearTimeout(this.timer);
this.timer = setTimeout(this.loadLog, pollingInterval);
}
}
Expand Down

0 comments on commit a51903f

Please sign in to comment.