Skip to content

WebSocketRateLimiter name no longer matches its scope — reused by HTTP middleware and accept-level connection limiting #528

Description

@bug-ops

Description

security::rate_limit::WebSocketRateLimiter is named after its original WebSocket-upgrade use case, but is now a general-purpose per-IP tracked-client rate limiter reused by three unrelated consumers:

  1. infrastructure::websocket::server/security.rs — its original purpose (per-IP WebSocket connection limiting).
  2. infrastructure::http::middleware::RateLimitMiddleware — generic per-request HTTP rate limiting (middleware.rs:240-277), unrelated to WebSocket.
  3. infrastructure::http::serve::serve_with_limits (new in serve_with_limits: no http2 max_concurrent_streams cap, header_read_timeout is http1-only #525/fix(http,security)!: harden serve_with_limits accept loop against #525/#526 #527) — accept-level per-IP TCP connection capping, before any HTTP request or WebSocket upgrade is parsed.

serve.rs's own doc comments (serve.rs:146, :252, :291, :377) already have to explain away the name three times ("reusing the existing WebSocketRateLimiter", "instead of reusing WebSocketRateLimiter's fail-closed default", etc.) — a sign the type's name is actively working against readability at its newest call site.

This was already touched on tangentially by #346 ("HTTP rate limiter's per-IP client map (WebSocketRateLimiter) is never pruned", closed) without renaming the type. The type is pub-exported at the crate root (lib.rs:100) and via security.rs:16, so a rename is a semver-breaking, deliberate API change rather than a drive-by fix — filed as a tracked research/refactor item rather than fixed inline during this cycle's audit.

Reproduction Steps

Not a functional bug — no repro. Structural/naming finding only.

Expected Behavior

A generic per-IP tracked-client rate limiter (used across WebSocket, HTTP middleware, and accept-level TCP contexts) should have a name that reflects its actual general-purpose scope, e.g. PerIpConnectionLimiter or ClientRateLimiter, with WebSocketRateLimiter (if kept at all) reserved for a WebSocket-specific wrapper or type alias.

Actual Behavior

The type's name still says "WebSocket" while its three real call sites are WebSocket, generic HTTP, and raw TCP accept-level limiting — none of which is uniquely a WebSocket concern anymore.

Environment

  • Version: commit d37d0eb (HEAD as of cycle 033)
  • Features: http-server, websocket-server
  • Platform: n/a (naming/API-clarity finding, not platform-specific)

Logs / Evidence

  • crates/pjs-core/src/security/rate_limit.rs:228pub struct WebSocketRateLimiter
  • crates/pjs-core/src/infrastructure/http/middleware.rs:240-277 — generic HTTP middleware use
  • crates/pjs-core/src/infrastructure/http/serve.rs:146,252,291,377 — accept-level TCP use, with doc comments explaining the name mismatch
  • Prior related issue: P2: HTTP rate limiter's per-IP client map (WebSocketRateLimiter) is never pruned #346 (closed, did not rename)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P4Nice-to-have — new SIMD targets, allocator experiments, new examplesarchitectureArchitecture / DDD / hexagonal-layering findingsinfrastructureInfrastructure layer changes (Clean Architecture)refactorCode refactoring without changing functionalitysecuritySecurity issues or improvements

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions