diff options
author | Clement Ho <clemmakesapps@gmail.com> | 2017-02-27 18:17:47 +0000 |
---|---|---|
committer | Ruben Davila <rdavila84@gmail.com> | 2017-02-27 23:50:58 -0500 |
commit | b57e8a4f4c329ff646bc906d3592a636f94163d6 (patch) | |
tree | 87ef7cc593785b27ca576f559b36f0a7ef48c3e6 | |
parent | 39569ee94f52b7c0f3d0d7f4bd9f853bdc616327 (diff) | |
download | gitlab-ce-b57e8a4f4c329ff646bc906d3592a636f94163d6.tar.gz |
Merge branch '28212-avoid-dos-on-build-trace' into 'master'
Replace setInterval with setTimeout to prevent highly frequent requests
Closes #28212
See merge request !9271
-rw-r--r-- | app/assets/javascripts/build.js | 33 | ||||
-rw-r--r-- | changelogs/unreleased/28212-avoid-dos-on-build-trace.yml | 4 |
2 files changed, 24 insertions, 13 deletions
diff --git a/app/assets/javascripts/build.js b/app/assets/javascripts/build.js index 0152be88b48..d6813089f08 100644 --- a/app/assets/javascripts/build.js +++ b/app/assets/javascripts/build.js @@ -7,7 +7,7 @@ var DOWN_BUILD_TRACE = '#down-build-trace'; this.Build = (function() { - Build.interval = null; + Build.timeout = null; Build.state = null; @@ -31,7 +31,7 @@ this.$scrollBottomBtn = $('#scroll-bottom'); this.$buildRefreshAnimation = $('.js-build-refresh'); - clearInterval(Build.interval); + clearTimeout(Build.timeout); // Init breakpoint checker this.bp = Breakpoints.get(); @@ -52,17 +52,7 @@ this.getInitialBuildTrace(); this.initScrollButtonAffix(); } - if (this.buildStatus === "running" || this.buildStatus === "pending") { - Build.interval = setInterval((function(_this) { - // Check for new build output if user still watching build page - // Only valid for runnig build when output changes during time - return function() { - if (_this.location() === _this.pageUrl) { - return _this.getBuildTrace(); - } - }; - })(this), 4000); - } + this.invokeBuildTrace(); } Build.prototype.initSidebar = function() { @@ -83,6 +73,22 @@ return window.location.href.split("#")[0]; }; + Build.prototype.invokeBuildTrace = function() { + var continueRefreshStatuses = ['running', 'pending']; + // Continue to update build trace when build is running or pending + if (continueRefreshStatuses.indexOf(this.buildStatus) !== -1) { + // Check for new build output if user still watching build page + // Only valid for runnig build when output changes during time + Build.timeout = setTimeout((function(_this) { + return function() { + if (_this.location() === _this.pageUrl) { + return _this.getBuildTrace(); + } + }; + })(this), 4000); + } + }; + Build.prototype.getInitialBuildTrace = function() { var removeRefreshStatuses = ['success', 'failed', 'canceled', 'skipped']; @@ -113,6 +119,7 @@ if (log.state) { _this.state = log.state; } + _this.invokeBuildTrace(); if (log.status === "running") { if (log.append) { $('.js-build-output').append(log.html); diff --git a/changelogs/unreleased/28212-avoid-dos-on-build-trace.yml b/changelogs/unreleased/28212-avoid-dos-on-build-trace.yml new file mode 100644 index 00000000000..800e0389c86 --- /dev/null +++ b/changelogs/unreleased/28212-avoid-dos-on-build-trace.yml @@ -0,0 +1,4 @@ +--- +title: Replace setInterval with setTimeout to prevent highly frequent requests +merge_request: 9271 +author: Takuya Noguchi |