Skip to content

Introduce conditional throttle#4

Open
michalmuskala wants to merge 2 commits into
mainfrom
conditional-throttle
Open

Introduce conditional throttle#4
michalmuskala wants to merge 2 commits into
mainfrom
conditional-throttle

Conversation

@michalmuskala

Copy link
Copy Markdown
Owner

No description provided.

Comment thread lib/rule.ex

"""
@spec conditional_throttle(Plug.Conn.t, term, Keyword.t) :: PlugAttack.rule
def conditional_throttle(conn, key, opts) do

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

@ericmj What do you think about this? Would this work for hexpm?

Comment thread lib/rule.ex

## Race conditions

Because the counter is imcremented lazily, there's a possible race condition,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

incremented*

Comment thread lib/rule.ex
if rem >= 0 do
Plug.Conn.register_before_send(conn, fn conn ->
before_send_throttle(conn, storage, key, now, period, expires_at, limit, rem)
end)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

If this returns a conn it should be added to the PlugAttack.rule type right?

@ericmj

ericmj commented Jul 24, 2017

Copy link
Copy Markdown

Ping? :)

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.

2 participants