Troubleshooting bunqueue: Common Issues & Fixes
Solutions to common issues when using bunqueue.
Installation Issues
Section titled “Installation Issues””bunqueue requires Bun runtime”
Section titled “”bunqueue requires Bun runtime””bunqueue only works with Bun, not Node.js.
# Check if Bun is installedbun --version
# Install Bun if neededcurl -fsSL https://bun.sh/install | bashPermission errors on install
Section titled “Permission errors on install”# Try with sudo (not recommended)sudo bun add bunqueue
# Better: fix npm permissionsmkdir ~/.bunchown -R $(whoami) ~/.bunDatabase Issues
Section titled “Database Issues””SQLITE_BUSY: database is locked”
Section titled “”SQLITE_BUSY: database is locked””Multiple processes trying to write simultaneously.
Solutions:
- Use WAL mode (default in bunqueue)
- Ensure only one server instance per database file
- Use server mode for multi-process access
# Check for multiple processeslsof ./data/queue.db
# Kill stale processespkill -f bunqueue”SQLITE_CORRUPT: database disk image is malformed”
Section titled “”SQLITE_CORRUPT: database disk image is malformed””Database corruption, usually from crash during write.
Solutions:
- Restore from S3 backup
- Delete and recreate database (data loss)
# Restore from backupbunqueue backup listbunqueue backup restore <key> --force
# Or recreate (loses data)rm ./data/queue.db*bunqueue startDatabase file keeps growing
Section titled “Database file keeps growing”SQLite doesn’t automatically reclaim space.
# Vacuum the database (run when server is stopped)sqlite3 ./data/queue.db "VACUUM;"
# Enable auto-vacuum (before creating database)sqlite3 ./data/queue.db "PRAGMA auto_vacuum = INCREMENTAL;"Embedded Mode Issues
Section titled “Embedded Mode Issues””Command timeout” error
Section titled “”Command timeout” error”error: Command timeout queue: "my-queue", context: "pull"This error means your Worker is trying to connect to a TCP server instead of using embedded mode.
Solution: Add embedded: true to both Queue and Worker:
// WRONG - Worker defaults to TCP modeconst queue = new Queue('tasks', { embedded: true });const worker = new Worker('tasks', processor); // Missing embedded: true!
// CORRECT - Both have embedded: trueconst queue = new Queue('tasks', { embedded: true });const worker = new Worker('tasks', processor, { embedded: true });SQLite database not created
Section titled “SQLite database not created”The database is only created when DATA_PATH is set.
Solution:
// Set DATA_PATH BEFORE importing bunqueueimport { mkdirSync } from 'fs';mkdirSync('./data', { recursive: true });process.env.DATA_PATH = './data/bunqueue.db';
// Then importimport { Queue, Worker } from 'bunqueue/client';Jobs not persisted across restarts
Section titled “Jobs not persisted across restarts”If you’re using multiple files, the Worker’s autorun: true (default) can cause the QueueManager to initialize before DATA_PATH is set.
Solution: Use autorun: false and start the worker manually:
const worker = new Worker('tasks', processor, { embedded: true, autorun: false, // Don't start automatically});
export function startWorker() { worker.run();}process.env.DATA_PATH = './data/bunqueue.db';
import { startWorker } from './queue';startWorker(); // Start after DATA_PATH is setJob Processing Issues
Section titled “Job Processing Issues”Jobs stuck in “active” state
Section titled “Jobs stuck in “active” state”Worker crashed while processing.
Solutions:
- Enable stall detection
- Restart workers
queue.setStallConfig({ enabled: true, stallInterval: 30000, maxStalls: 3,});Jobs not being processed
Section titled “Jobs not being processed”Check these:
- Is the queue paused?
- Is there a worker for this queue?
- Is rate limiting blocking jobs?
// Check if pausedconst isPaused = queue.isPaused();
// Check countsconst counts = queue.getJobCounts();console.log(counts);
// Check rate limitconst config = queue.getRateLimit();Jobs failing immediately
Section titled “Jobs failing immediately”Check the error in failed event:
worker.on('failed', (job, error) => { console.error('Job failed:', error); console.error('Job data:', job.data); console.error('Attempts:', job.attemptsMade);});Memory usage keeps growing
Section titled “Memory usage keeps growing”Possible causes:
- Jobs not being removed after completion
- Too many jobs in DLQ
- Memory leak in processor
// Enable removeOnCompleteawait queue.add('task', data, { removeOnComplete: true,});
// Purge old DLQ entriesqueue.purgeDlq();
// Check for leaks in processorworker.on('completed', () => { console.log('Memory:', process.memoryUsage().heapUsed);});Connection Issues
Section titled “Connection Issues””Connection refused” to server
Section titled “”Connection refused” to server”Server not running or wrong port.
# Check if server is runningps aux | grep bunqueue
# Check listening portslsof -i :6789lsof -i :6790
# Start serverbunqueue startTCP connection drops
Section titled “TCP connection drops”Network issues or server overload.
// Add reconnection logiclet client = createClient();
client.on('error', async () => { await sleep(1000); client = createClient();});Authentication failures
Section titled “Authentication failures”# Check token is setecho $AUTH_TOKENS
# Test with curlcurl -H "Authorization: Bearer your-token" \ http://localhost:6790/healthPerformance Issues
Section titled “Performance Issues”Slow job processing
Section titled “Slow job processing”Optimize:
- Increase worker concurrency
- Use batch operations
- Check database I/O
// Increase concurrencyconst worker = new Worker('queue', processor, { concurrency: 20,});
// Use bulk addawait queue.addBulk([...jobs]);
// Use bulk ackawait queue.ackBatch([...jobIds]);High latency on pull
Section titled “High latency on pull”Check:
- Index on queue table
- Too many delayed jobs
- Database on slow disk
-- Check indexes exist.indices jobs
-- Check delayed jobs countSELECT COUNT(*) FROM jobs WHERE state = 'delayed';Server CPU at 100%
Section titled “Server CPU at 100%”Too many connections or jobs.
# Check connection countbunqueue stats
# Reduce polling frequency# Add backoff in clientsBackup Issues
Section titled “Backup Issues”S3 backup failing
Section titled “S3 backup failing”# Check credentialsecho $S3_ACCESS_KEY_IDecho $S3_BUCKET
# Test connectivityaws s3 ls s3://$S3_BUCKET/
# Check logsbunqueue backup statusRestore failing
Section titled “Restore failing”# List available backupsbunqueue backup list
# Force restore (overwrites existing)bunqueue backup restore <key> --forceSandboxed Worker Issues
Section titled “Sandboxed Worker Issues”Segmentation fault when terminating workers
Section titled “Segmentation fault when terminating workers”If you experience crashes (segfaults) when using SandboxedWorker, especially during worker timeout or error handling, this is a known Bun bug.
Symptoms:
Segmentation fault at address 0xE8Worker has been terminatederrors- Crashes during
worker.terminate()calls - Unexpected memory growth or thread duplication (#52)
Solution: Switch to the standard Worker for production workloads:
// ❌ SandboxedWorker — experimental, may crashconst worker = new SandboxedWorker('queue', { processor: './processor.ts', concurrency: 4,});
// ✅ Worker — stable, production-ready, same functionalityconst worker = new Worker('queue', async (job) => { // same logic from your processor.ts return result;}, { embedded: true, concurrency: 4 });If you must use SandboxedWorker:
- Pin your Bun version — behavior varies across releases
- Use graceful shutdown (
await worker.stop()) instead of force termination - Use longer timeout values to avoid frequent terminations
- Monitor memory usage closely
These issues will be resolved when Bun stabilizes their Worker API.
Common Error Messages
Section titled “Common Error Messages”| Error | Cause | Solution |
|---|---|---|
Command timeout | Worker missing embedded: true | Add embedded: true to Worker options |
SQLITE_BUSY | Database locked | Use single writer |
SQLITE_FULL | Disk full | Free disk space |
ECONNREFUSED | Server not running | Start server or use embedded mode |
ETIMEDOUT | Network issue | Check connectivity |
Job not found | Already completed/removed | Check job lifecycle |
Segmentation fault | Bun Worker termination bug | Use graceful shutdown, see above |
Debug Mode
Section titled “Debug Mode”Enable verbose logging:
# Server modeLOG_FORMAT=json DEBUG=bunqueue:* bunqueue start
# Check logstail -f /var/log/bunqueue.logGetting Help
Section titled “Getting Help”If these solutions don’t help:
- Check GitHub Issues
- Search Discussions
- Open a new issue with:
- bunqueue version
- Bun version
- OS and hardware
- Error message and stack trace
- Minimal reproduction code