You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
## Problem
The `BatchQueue` implementation in `sequencers/single/queue.go` had **no
size limits**, leading to potential resource exhaustion and system
instability. During DA congestion or connection issues, batches would
accumulate faster than they could be processed, causing:
- **Unbounded memory growth** from unlimited slice expansion
- **Unbounded disk usage** from persistent storage without cleanup
- **No backpressure mechanism** to signal upstream components when
overwhelmed
- **Performance degradation** during restart recovery with large
persistent queues
## Solution
Added configurable queue limits with graceful error handling while
maintaining full backward compatibility:
### Key Changes
1. **New Error Type for Backpressure**
```go
var ErrQueueFull = errors.New("batch queue is full")
```
2. **Enhanced BatchQueue Structure**
```go
type BatchQueue struct {
queue []coresequencer.Batch
maxQueueSize int // 0 = unlimited for backward compatibility
mu sync.Mutex
db ds.Batching
}
```
3. **Throttling Logic in AddBatch**
```go
// Check if queue is full (maxQueueSize of 0 means unlimited)
if bq.maxQueueSize > 0 && len(bq.queue) >= bq.maxQueueSize {
return ErrQueueFull
}
```
4. **Production-Ready Defaults**
- Set default limit of 1000 batches in single sequencer
- Enhanced error logging when queue reaches capacity
- Graceful error propagation with informative messages
### Backward Compatibility
- Existing tests use `maxSize: 0` (unlimited) to maintain current
behavior
- All existing functionality preserved
- No breaking changes to public APIs
### Test Coverage
Added comprehensive test suites covering:
- Various queue size limits (unlimited, within limit, at limit,
exceeding limit)
- Queue behavior after batch processing (demonstrates backpressure
relief)
- Thread safety under concurrent load (100 workers, 10 queue limit)
- End-to-end integration testing with sequencer
**Coverage increased from 76.7% to 78.0%**
### Example Behavior
```go
// During normal operation
queue := NewBatchQueue(db, "batches", 1000)
err := queue.AddBatch(ctx, batch) // ✅ Success
// During DA congestion (queue full)
err := queue.AddBatch(ctx, batch) // ❌ Returns ErrQueueFull
// After DA processes batches
batch, _ := queue.Next(ctx) // Frees space
err = queue.AddBatch(ctx, batch) // ✅ Success again
```
This prevents the resource exhaustion scenarios while allowing normal
operation and providing clear backpressure signals to upstream
components.
Fixes#2252.
<!-- START COPILOT CODING AGENT TIPS -->
---
💬 Share your feedback on Copilot coding agent for the chance to win a
$200 gift card! Click
[here](https://survey.alchemer.com/s3/8343779/Copilot-Coding-agent) to
start the survey.
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: Manav-Aggarwal <16928547+Manav-Aggarwal@users.noreply.github.com>
Co-authored-by: Manav Aggarwal <manavaggarwal1234@gmail.com>
0 commit comments