Pumpkin-MC/Pumpkin · warning · InventoryError

Unable to lock

Error message

Unable to lock

What it means

InventoryError::LockError indicates the library failed to acquire a lock on an inventory or slot while processing an inventory interaction. Pumpkin inventories are shared mutable state guarded by locks (e.g. Mutex/RwLock); this error surfaces when the lock cannot be obtained instead of blocking or panicking.

Solutions

  1. Check whether the lock acquisition uses try_lock; if so, retry on the next tick or queue the operation
  2. Serialize inventory mutations on the main server thread to avoid contention
  3. Log the conflicting actors to identify which systems contend for the same inventory
  4. Avoid holding inventory locks across await points or long operations

Example fix

// before
let mut slot = inventory.try_lock_slot(idx).map_err(|_| InventoryError::LockError)?;
// after
let mut slot = match inventory.try_lock_slot(idx) {
    Ok(s) => s,
    Err(_) => return Ok(()), // retry on next interaction; don't error the player
};
Defensive patterns

Strategy: retry

Try / catch

match inv.try_lock_slot(idx) {
    Err(InventoryError::LockError) => {
        // retry next tick or queue the operation instead of failing the player
    }
    r => r?,
}

Prevention

When it happens

Trigger: Concurrent inventory operations on the same container/slot — e.g. two threads (player packet handler and another system like hopper or drag logic) calling into inventory APIs that take the lock simultaneously and the acquisition path reports failure.

Common situations: Multiple players manipulating the same chest in the same tick; async tasks contending for a player's inventory during rapid clicks; plugins/systems mutating inventory from outside the main thread.

Related errors


AI-assisted analysis of Pumpkin-MC/Pumpkin@8d4639e25a (2026-09-09). Data as JSON: /api/errors/dc0aef97435a80ce. Report an issue: GitHub.

Appendix: source

Thrown at crates/pumpkin-inventory/src/error.rs:10

use thiserror::Error;

/// Errors that can occur during inventory operations.
///
/// These errors represent various failure conditions when handling inventory
/// interactions, such as invalid slot indices, permission issues, or protocol errors.
#[derive(Error, Debug)]
pub enum InventoryError {
    /// Failed to acquire a lock on an inventory or slot.
    #[error("Unable to lock")]
    LockError,
    /// The specified slot index is invalid or out of bounds.
    #[error("Invalid slot")]
    InvalidSlot,
    /// A player attempted to interact with a container that is closed.
    ///
    /// The parameter is the player's entity ID.
    #[error("Player '{0}' tried to interact with a closed container")]
    ClosedContainerInteract(i32),
    /// Multiple players attempted to drag items in the same container simultaneously.
    #[error("Multiple players dragging in a container at once")]
    MultiplePlayersDragging,
    /// Drag operation was performed out of order (e.g., end before start).
    #[error("Out of order dragging")]
    OutOfOrderDragging,
    /// The received inventory packet is malformed or invalid.
    #[error("Invalid inventory packet")]
    InvalidPacket,

View on GitHub (pinned to 8d4639e25a)