Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backend throttling for getPartialFeedback #1750

Merged
merged 6 commits into from
Feb 3, 2023
Merged

Conversation

michellexliu
Copy link
Contributor

@michellexliu michellexliu commented Jan 31, 2023

Resolves #1661

Description

Updates rack-attack.rb to throttle getPartialFeedback from the backend & fixes error that occurs when throttling all other endpoints.

Motivation and Context

Previously, getPartialFeedback was only throttled via the frontend. Students would be able to get past this frontend throttling by writing a script, or by doing an entire webpage refresh rather than an interface refresh. If abused, this could overload Tango with too many requests, thus necessitating backend throttling.

Additionally, previously, if env['rack.attack.match_data'] returned nil, an error was raised in the overloaded throttled_response method. This error would prevent the endpoints from actually being throttled.

How Has This Been Tested?

Note: must first activate cache on the development build using rails dev:cache. This can be confirmed by checking for the existence of a tmp/caching-dev.txt file.

  • Calls getPartialFeedback normally after waiting 5 seconds
  • 429 error is returned after doing successive page refreshes
  • 429 error is returned properly when frontend throttling is disabled and refresh button is spammed
    To disable frontend throttling, replace onClickRefresh with const onClickRefresh = () => refreshPartial(true); in app/views/assessments/_partial_feedback_js.html.erb

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • I have run rubocop for style check. If you haven't, run overcommit --install && overcommit --sign to use pre-commit hook for linting
  • My change requires a change to the documentation, which is located at Autolab Docs
  • I have updated the documentation accordingly, included in this PR

@victorhuangwq
Copy link
Contributor

I tested the following:

429 error is returned properly when frontend throttling is disabled and refresh button is spammed
To disable frontend throttling, replace onClickRefresh with const onClickRefresh = () => refreshPartial(true); in app/views/assessments/_partial_feedback_js.html.erb

Specifically this is a code snippet of what I have changed:


  refreshPartial(false);

  const onClickRefresh = () => refreshPartial(true);

  const rotateIcon = () => {
    const icon = $('.refresh-feedback');
    if(!icon.hasClass("loading")) {
	    icon.addClass('loading');
      setTimeout(() => icon.removeClass('loading'), 1000);
    }
  }

  $('.refresh-feedback')[0].addEventListener("click", onClickRefresh);
  $('.refresh-feedback')[0].addEventListener("click", rotateIcon);

However, I don't think I see any throttling, or 429 errors popping up for me?

image

Copy link
Contributor

@victorhuangwq victorhuangwq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

Tested by activating cache on the development build using rails dev:cache

Deactivated frontend throttling, and backend throttling kicks in. 5 seconds does feels a bit longer than expected between wait - but I guess the front end throttling is also 5 seconds too?

image

@michellexliu michellexliu merged commit 4a68547 into master Feb 3, 2023
@michellexliu michellexliu deleted the backend-throttling branch February 3, 2023 22:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Throttle getPartialFeedback endpoint from backend
2 participants