The HTTP 423 status code stands for "Locked". It is a client error response indicating that the resource the client is trying to access is currently locked and cannot be modified or accessed as requested.
When is HTTP 423 Used?
- The 423 Locked response is returned when a resource is temporarily locked due to some form of conflict or restriction that prevents the client from making modifications or accessing it.
- This status is commonly used in webDAV (Web Distributed Authoring and Versioning) applications, where resources such as files or directories are locked to prevent concurrent or conflicting changes by multiple clients.
Common Causes of HTTP 423 Errors
- Resource locking: The resource (file, document, or data) is locked by another process or user, and the client is unable to modify or access it.
- File or database locking: A server may lock a file or database record while it is being edited or updated to prevent conflicting changes.
- Access control: The resource may be locked due to access control policies or restrictions, meaning that only certain users or processes can unlock it.
Example Scenarios
- A user tries to edit a document that is currently locked by another user, so the server returns a 423 error to indicate that the document cannot be modified at this time.
- A client tries to update a file on a webDAV server, but the file is locked to prevent concurrent edits, and the server responds with a 423 status code.
Example
Client Request (Locked Resource)
PUT /documents/project.docx HTTP/1.1
Host: example.com
Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document
Content-Length: 1234
<file content>
(The client attempts to upload a new version of a document, but the document is locked and cannot be modified.)
Server Response (423 Locked)
HTTP/1.1 423 Locked
Content-Type: application/json
{
"error": "The resource is currently locked. Please try again later."
}
Best Practices for Handling HTTP 423
- Inform the client: The response should clearly explain that the resource is locked and indicate whether it will be available at a later time or what actions are required to unlock it.
- Provide a mechanism for unlocking: In scenarios where resources are locked for editing or access, it is helpful to provide a way for users or processes to unlock the resource once they are done or if they have the appropriate permissions.
- Retry mechanisms: If possible, clients can be instructed to retry the request after some time, once the resource has been unlocked.
- Concurrency management: Implement robust locking mechanisms that ensure resources are locked only when necessary and automatically unlocked after use to minimize conflicts.
Summary
HTTP 423 is used when a resource is locked and cannot be accessed or modified by the client at that moment. This often happens in systems with resource locking mechanisms, such as file editing or database systems, where concurrent access must be controlled. The client is usually expected to wait or retry the request once the lock is released.