# 508 Loop Detected

> https://http-status.org/docs/508

**Family:** 5xx Server Error

## Rationale

The server detected an infinite loop while processing the request (WebDAV).

## In Plain Terms

The server followed references while walking through folders and found a cycle, so it stopped instead of going in circles forever.

## Description

The HTTP 508 Loop Detected status code indicates that the server terminated an operation because it encountered an infinite loop while processing a WebDAV request, commonly during a Depth: infinity traversal.

## Server Perspective

### Usage
- Return 508 when a recursive or Depth: infinity operation cannot finish due to cyclic bindings or references
- Use it when the entire operation fails because loop detection is required to prevent unbounded traversal
- WebDAV Depth: infinity operations encounter cyclic bindings or recursive references
- Collection traversal would loop forever without explicit detection
- The server must stop the entire operation because the requested graph of resources is cyclic

### Implementation
- Track visited resources or bindings during traversal so loops are detected deterministically
- Prefer 208 Already Reported inside Multi-Status when you can complete the response safely without repeating members

### Common Headers
- No status-specific header is required; standard WebDAV response metadata may still apply

### Body
- A body is recommended; explain that a cyclic reference or traversal loop was detected and include enough safe detail for operators or clients to find the offending structure

### Pitfalls
- Do not use 508 for ordinary deep trees that are merely slow but not cyclic
- Do not use 508 when duplicate suppression with 208 Already Reported would let the operation succeed
- The server can complete the operation and suppress duplicates inside a Multi-Status response (consider 208 Already Reported)
- A single resource is locked or unavailable for other reasons (use a more specific WebDAV status such as 423 Locked)
- Generic server failures unrelated to cyclic traversal (use 500 Internal Server Error or another specific 5xx)

## Client Perspective

### Pitfalls
- Do not treat 508 like a transient network timeout
- Do not assume the target resource is missing or locked without checking the response details

## Examples

### Recursive WebDAV traversal hits cyclic binding

The server discovered a reference cycle while enumerating the collection tree and aborted the request.

**Request:**
```
PROPFIND https://api.example.test/collection
```

**Response:**
```
508 Loop Detected
Content-Type: application/json

{
  "error": "loop_detected"
}
```

## Related Codes

- [207 Multi-Status](/docs/207.md)
- [208 Already Reported](/docs/208.md)
- [507 Insufficient Storage](/docs/507.md)

