Skip to content

508 Loop Detected

Description

The 508 Loop Detected status code indicates that the server detected an infinite loop while processing a request. This status code is specific to WebDAV (Web Distributed Authoring and Versioning) and is typically encountered when processing a request that involves following relationships between resources.

This error occurs when the server detects a circular reference that would cause an infinite loop, such as:

  • A resource that contains a reference to itself (directly or indirectly)
  • A chain of references that eventually leads back to the starting resource
  • A binding structure in WebDAV that creates a circular hierarchy
  • Redirects that form a loop

The 508 status code is defined in RFC 5842 as part of the WebDAV Binding Extensions, but it can be used in any HTTP application where infinite loops might be detected during request processing.

Syntax

HTTP/1.1 508 Loop Detected
Content-Type: application/json
Content-Length: 176

{
  "error": {
    "code": 508,
    "message": "Loop Detected",
    "details": "The server detected an infinite loop while processing the request."
  }
}

Examples

Example 1: WebDAV Circular Reference

A WebDAV client attempts to perform an operation on a collection that contains a circular reference in its binding structure.

Request:

PROPFIND /collection/ HTTP/1.1
Host: webdav.example.com
Depth: infinity
Content-Type: application/xml
Content-Length: 124
Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ=

<?xml version="1.0" encoding="utf-8" ?>
<D:propfind xmlns:D="DAV:">
  <D:prop>
    <D:resourcetype/>
  </D:prop>
</D:propfind>

Response:

HTTP/1.1 508 Loop Detected
Content-Type: application/json
Content-Length: 219

{
  "error": {
    "code": 508,
    "message": "Loop Detected",
    "details": "The server detected a circular reference in the collection hierarchy. The collection '/collection/sub/back/' refers back to '/collection/'."
  }
}

Example 2: API Resource Dependency Loop

An API server detects a circular dependency when trying to resolve nested resources.

Request:

GET /api/resources/123?include=dependencies HTTP/1.1
Host: api.example.com
Accept: application/json
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...

Response:

HTTP/1.1 508 Loop Detected
Content-Type: application/json
Content-Length: 241

{
  "error": {
    "code": 508,
    "message": "Loop Detected",
    "details": "The server detected a circular dependency: Resource 123 depends on Resource 456, which depends on Resource 789, which depends on Resource 123."
  }
}

Example 3: Recursive Document Processing

A document processing service detects a loop when processing a document with recursive includes.

Request:

POST /api/documents/process HTTP/1.1
Host: docs.example.com
Content-Type: application/json
Content-Length: 152
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...

{
  "document_id": "doc-123",
  "operations": ["resolve_includes", "generate_toc", "validate_links"],
  "output_format": "pdf"
}

Response:

HTTP/1.1 508 Loop Detected
Content-Type: application/json
Content-Length: 232

{
  "error": {
    "code": 508,
    "message": "Loop Detected",
    "details": "The document contains a circular reference in its include directives. Document 'doc-123' includes 'doc-456' which includes 'doc-123' again."
  }
}

Summary

The 508 Loop Detected status code indicates that the server detected an infinite loop while processing a request. It's primarily used in WebDAV and similar protocols that involve operations on resources with relationships to other resources.

Key points about 508 Loop Detected:

  1. It's defined in WebDAV Binding Extensions (RFC 5842) but can be used in any HTTP application
  2. It indicates a circular reference that would cause an infinite loop during processing
  3. It's a client error in the sense that the client's request cannot be fulfilled due to the loop
  4. It's different from a server timeout (504) which occurs when a server takes too long to respond
  5. The response should include information about the detected loop to help the client resolve the issue
  6. It's commonly encountered in systems that process hierarchical structures, dependencies, or references
  7. Clients receiving this status should examine and fix the circular references in their resource structure
  8. The condition is usually permanent unless the client modifies the resource relationships