Skip to content

fix(transport): prevent file log duplication from overlapping batch f…#87

Merged
webcoderspeed merged 1 commit into
mainfrom
fix/file-transport-batch-flush-race
Jun 4, 2026
Merged

fix(transport): prevent file log duplication from overlapping batch f…#87
webcoderspeed merged 1 commit into
mainfrom
fix/file-transport-batch-flush-race

Conversation

@webcoderspeed

Copy link
Copy Markdown
Collaborator

…lushes

FileTransport.addToBatch() fires flush() un-awaited on every Nth entry, so a synchronous burst of writes (e.g. a buffered-log flush replaying many entries) triggers many overlapping flushes. Each flush snapshotted [...this.batch] and only cleared the batch AFTER its async write resolved, so concurrent flushes re-snapshotted the same not-yet-cleared entries and wrote them again — turning N log calls into N-squared file lines. The console transport was unaffected because it writes synchronously with no batch window.

Serialize flushes through a single shared drain promise and detach the batch synchronously before awaiting, so entries are written exactly once. Also cancel any pending interval timer when a threshold flush starts.

Adds regression tests covering a 500-entry un-awaited burst and concurrent flush() calls.

Pull Request

📋 Description

What does this PR do?

Why is this change needed?

Related Issues

  • Fixes #
  • Related to #

🔄 Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✨ New feature (non-breaking change that adds functionality)
  • 💥 Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • 📚 Documentation update
  • 🧹 Code cleanup/refactoring
  • ⚡ Performance improvement
  • 🧪 Test improvements
  • 🔧 Build/CI improvements

🧪 Testing

Test Coverage

  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have tested this change manually

Test Details

# Commands used for testing
npm test
npm run test:coverage
npm run lint

Manual Testing

📖 Documentation

  • Code comments updated
  • README.md updated
  • API documentation updated
  • Examples updated
  • CHANGELOG.md updated (for significant changes)

🔍 Code Quality

  • My code follows the project's style guidelines
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings or errors
  • I have run the linter and fixed any issues

📦 Dependencies

  • No new dependencies added
  • New dependencies are justified and documented
  • Dependencies are pinned to specific versions
  • Security implications have been considered

🚀 Performance

  • No performance impact
  • Performance impact is minimal and justified
  • Performance improvements included
  • Benchmarks provided (if applicable)

🔒 Security

  • No security implications
  • Security implications have been considered and addressed
  • No sensitive data exposed
  • Input validation added where necessary

📱 Compatibility

  • Node.js versions:
  • Operating Systems:
  • Breaking changes documented
  • Migration guide provided (if needed)

🎃 Hacktoberfest

  • This is a Hacktoberfest contribution
  • I have read and followed the contribution guidelines
  • This PR provides meaningful value (not spam)
  • I understand the project's goals and scope

📸 Screenshots/Examples

Before

After

Code Example

// Example of how to use the new feature
import { Logixia } from 'logixia';

const logger = new Logixia({
  // example configuration
});

// example usage

🔗 Additional Context

Deployment Notes

Rollback Plan

Future Considerations

✅ Reviewer Checklist

  • Code quality meets project standards
  • Tests are comprehensive and pass
  • Documentation is updated and clear
  • Breaking changes are properly documented
  • Security implications reviewed
  • Performance impact acceptable
  • Ready for merge

📝 Notes for Reviewers

🙏 Acknowledgments


Thank you for contributing to Logixia! 🚀

…lushes

FileTransport.addToBatch() fires flush() un-awaited on every Nth entry, so a
synchronous burst of writes (e.g. a buffered-log flush replaying many entries)
triggers many overlapping flushes. Each flush snapshotted [...this.batch] and
only cleared the batch AFTER its async write resolved, so concurrent flushes
re-snapshotted the same not-yet-cleared entries and wrote them again — turning
N log calls into N-squared file lines. The console transport was unaffected
because it writes synchronously with no batch window.

Serialize flushes through a single shared drain promise and detach the batch
synchronously before awaiting, so entries are written exactly once. Also cancel
any pending interval timer when a threshold flush starts.

Adds regression tests covering a 500-entry un-awaited burst and concurrent
flush() calls.
@github-actions

github-actions Bot commented Jun 4, 2026

Copy link
Copy Markdown

size-limit report 📦

Path Size
ESM (gzipped) 9.43 KB (+0.02% 🔺)
CJS (gzipped) 9.58 KB (+0.02% 🔺)

@webcoderspeed webcoderspeed merged commit 8b3be23 into main Jun 4, 2026
9 of 10 checks passed
@webcoderspeed webcoderspeed deleted the fix/file-transport-batch-flush-race branch June 4, 2026 16:07
@github-actions

Copy link
Copy Markdown

🎉 This issue has been resolved in version 1.10.2.
Install it: npm install logixia@1.10.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant