anza-xyz / anza-xyz/shaq

Allow write guards to be disarmed before drop

Open
#142 0 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Rust
Stars
26
Forks
8
Avg merge
16h 41m
Merged PRs (30d)
15

Description

## Problem

Shaq write guards publish their buffer when dropped. If a caller performs a fallible write directly into the buffer, an error can cause the guard to be dropped after only part of the value has been written. The incomplete or invalid buffer is then published to consumers.

For example:

```rust
wincode::serialize_into(guard.as_mut(), &event)?;
```

If serialization fails, error propagation drops the guard and publishes any bytes written before the failure.

## Proposed change

Add a method such as `disarm` or `abort` to write guards:

```rust
let mut guard = producer.write()?;

if let Err(err) = wincode::serialize_into(guard.as_mut(), &event) {
guard.disarm();
return Err(err);
}
```

Dropping an armed guard should preserve the existing publish-on-drop behavior. Dropping a disarmed guard should release or recycle the reserved slot without making its contents visible to consumers.

The change should be implemented for each write guard type in separate sub-issues.

## Acceptance criteria

- Write guards can be explicitly disarmed before they are dropped.
- Dropping an armed guard preserves the existing publish-on-drop behavior.
- Dropping a disarmed guard does not expose its buffer to consumers.
- The reserved slot is safely released or recycled for subsequent writes.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.