VOOZH about

URL: https://deepwiki.com/hypervel/redis/7.2-timeout-exceptions

⇱ Timeout Exceptions | hypervel/redis | DeepWiki


Loading...
Menu

Timeout Exceptions

Purpose and Scope

This document describes the LimiterTimeoutException thrown by the rate limiting system when a rate limit acquisition attempt exceeds the configured timeout period. This exception signals that a client could not acquire a rate limit slot within the allowed waiting time.

For information about the rate limiter implementation that throws this exception, see Duration Limiter.

Exception Overview

The LimiterTimeoutException is a specialized exception class used exclusively by the rate limiting subsystem to indicate timeout failures during rate limit acquisition attempts.

Class Definition

The exception is defined in src/Limiters/LimiterTimeoutException.php9-11 as a simple extension of PHP's base Exception class:


This minimal implementation relies on the parent Exception class for all standard exception behavior (message, code, stack trace, etc.).

Sources: src/Limiters/LimiterTimeoutException.php1-12

Exception Hierarchy

The following diagram shows the class hierarchy and the exception's position within PHP's exception system:


Sources: src/Limiters/LimiterTimeoutException.php9-11

Throwing Context

The LimiterTimeoutException is thrown during rate limit acquisition when the DurationLimiter::block() method times out waiting for an available slot in the rate limit window.

Rate Limiting Flow with Timeout


Sources: src/Limiters/LimiterTimeoutException.php9-11

Exception Characteristics

Exception Properties

PropertyValueDescription
NamespaceHypervel\Redis\LimitersScoped to rate limiting subsystem
Parent Class\ExceptionStandard PHP exception
Custom PropertiesNoneUses default exception properties
Custom MethodsNoneUses default exception methods

Thrown By

The exception is instantiated and thrown by:

  • DurationLimiter::block() - When timeout is reached before acquiring a rate limit slot

Message Content

When thrown, the exception typically carries a message indicating the timeout duration and the rate limit key that failed to acquire. The exact message is set by the throwing code in the DurationLimiter class.

Sources: src/Limiters/LimiterTimeoutException.php1-12

Exception Handling Patterns

Basic Exception Handling


Distinguishing from Other Exceptions

Since LimiterTimeoutException extends the base Exception class without additional properties, it is distinguished solely by its type. Applications should catch this specific exception type to handle rate limit timeouts differently from other failures.


Sources: src/Limiters/LimiterTimeoutException.php9-11

Integration with Rate Limiter

Exception Throwing Decision

The exception is thrown when all of the following conditions are met:

  1. A rate limit has been exceeded (no available slots)
  2. A blocking timeout has been specified
  3. The timeout duration has elapsed without acquiring a slot

Relationship to DurationLimiter Methods

MethodThrows Exception?Behavior on Limit Exceeded
tooManyAttempts()NoReturns true or false
attempt()NoReturns true or false
block()YesThrows LimiterTimeoutException on timeout

Only the block() method can throw this exception, as it is the only method that implements blocking/waiting behavior with a timeout.

Sources: src/Limiters/LimiterTimeoutException.php1-12

Code Entity Mapping

The following table maps natural language concepts to specific code entities in the codebase:

ConceptCode EntityFile Path
Timeout ExceptionLimiterTimeoutExceptionsrc/Limiters/LimiterTimeoutException.php9
Exception NamespaceHypervel\Redis\Limiterssrc/Limiters/LimiterTimeoutException.php5
Parent ClassExceptionsrc/Limiters/LimiterTimeoutException.php9 (PHP built-in)

Sources: src/Limiters/LimiterTimeoutException.php1-12

Best Practices

Exception Handling Guidelines

  1. Catch Specifically: Always catch LimiterTimeoutException explicitly rather than catching generic Exception when handling rate limit operations
  2. Return Appropriate HTTP Status: For API endpoints, return HTTP 429 (Too Many Requests) when this exception is caught
  3. Include Retry Information: When communicating timeout failures to clients, include information about when they can retry
  4. Log Thoughtfully: Timeout exceptions may be expected behavior under high load; log them at an appropriate level (info/warning rather than error)
  5. Consider Alternatives: If timeouts are frequent, consider increasing timeout duration, increasing rate limits, or implementing exponential backoff

Example: HTTP API Integration


Sources: src/Limiters/LimiterTimeoutException.php1-12

Summary

The LimiterTimeoutException is a simple, single-purpose exception class that serves as a typed signal for rate limit timeout failures. Its minimal implementation relies on standard PHP exception behavior, with its type serving as the primary distinguishing feature. Applications using the DurationLimiter::block() method must be prepared to catch and handle this exception appropriately.

Sources: src/Limiters/LimiterTimeoutException.php1-12