Runtime thread safety monitoring for concurrent Ruby code.
This gem provides a TracePoint-based ownership tracking system that detects when objects are accessed from multiple fibers or threads without proper synchronization. It helps catch concurrency bugs during development and testing with zero overhead in production.
Ruby's fiber-based concurrency (via async
) requires careful attention to object ownership. This gem helps you catch violations of the single-owner model in your test suite, preventing concurrency bugs from reaching production.
Enable it in your tests to get immediate feedback when objects are incorrectly shared across fibers.
Please see the project documentation for more details.
- Getting Started - This guide explains how to use
async-safe
to detect thread safety violations in your Ruby code.
Please see the project releases for all releases.
- Better error message.
- Inverted default model: classes are async-safe by default, use
ASYNC_SAFE = false
to enable tracking. - Added flexible
ASYNC_SAFE
constant support: boolean, hash, or array configurations. - Added
Class#async_safe!
method for marking classes. - Added
Class#async_safe?(method)
method for querying safety. - Removed logger feature: always raises
ViolationError
exceptions. - Removed
Async::Safe::Concurrent
module: useasync_safe!
instead.
Thread::Queue
transfers ownership of objects popped from it.- Add support for
logger:
option inAsync::Safe.enable!
which logs violations instead of raising errors.
- Implement TracePoint-based ownership tracking.
- Add
Async::Safe::Concurrent
module for marking thread-safe classes. - Add
thread_safe
class method for marking thread-safe methods. - Add
Async::Safe.transfer
for explicit ownership transfer - Add violation detection and reporting
- Zero overhead when monitoring is disabled
- async - Composable asynchronous I/O for Ruby.
- Thread Safety Guide - Best practices for concurrent Ruby code.
We welcome contributions to this project.
- Fork it.
- Create your feature branch (
git checkout -b my-new-feature
). - Commit your changes (
git commit -am 'Add some feature'
). - Push to the branch (
git push origin my-new-feature
). - Create new Pull Request.
In order to protect users of this project, we require all contributors to comply with the Developer Certificate of Origin. This ensures that all contributions are properly licensed and attributed.
This project is best served by a collaborative and respectful environment. Treat each other professionally, respect differing viewpoints, and engage constructively. Harassment, discrimination, or harmful behavior is not tolerated. Communicate clearly, listen actively, and support one another. If any issues arise, please inform the project maintainers.