Skip to content

add random timeout on deny#77

Open
Pofilo wants to merge 1 commit into
PascalMinder:mainfrom
Pofilo:add_random_timeout
Open

add random timeout on deny#77
Pofilo wants to merge 1 commit into
PascalMinder:mainfrom
Pofilo:add_random_timeout

Conversation

@Pofilo

@Pofilo Pofilo commented Mar 5, 2025

Copy link
Copy Markdown

When I receive a lot of requests, I may want to slow down a little bit (this will delay the next request).

Note that:

  • I'm not familiar with Go (I did not use any linters..)
  • I don't know the consequences of this sleep (will it block other goroutines? how limited is the pool?)

@Pofilo
Pofilo force-pushed the add_random_timeout branch from 299f5ac to c3c17ea Compare March 5, 2025 21:46
@Pofilo
Pofilo marked this pull request as draft March 5, 2025 21:57
@Pofilo
Pofilo marked this pull request as ready for review March 5, 2025 21:59
@PascalMinder

PascalMinder commented Jul 9, 2026

Copy link
Copy Markdown
Owner

No. The implementation is fine on that front, it only delays the response for the denied request itself. Go's net/http server dispatches each request to its own goroutine, and time. Sleep parks only the calling goroutine.

But if the intent is to slow down "a lot of simultaneous requests" the server needs to hold a connection for each request. This would mean rate x delayOnDenyMs. E.g. 1,000 req/s with a 2s delay means ~2,000 goroutines/connections held open concurrently. That can exhaust:

  • File descriptors (each open connection is one fd)
  • Memory, if the flood is large enough or delay long enough.
  • Traefik's own connection/listener limits, if configured (e.g. maxIdleConnsPerHost, transport limits)

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