Prerequisites
Description
We experienced a critical issue when producing Kafka messages where:
- The first message could sometimes be produced successfully.
- Producing a second message caused the application to crash.
- The application terminated with the following error:
Assertion failed: (r == 0), function rwlock_rdlock,
file tinycthread_extra.c, line 186.
No additional logs were emitted — even with debug logging enabled.
Environment
- .NET: version 10.0
- KafkaFlow: 4.1.0
- librdkafka version (if known): 12.13.1
- OS: Linux (Same behaviour on MacOS Tahoe 26.3)
- Hosting environment: AKS (Same behaviour locally)
Steps to reproduce
How We Were Registering Producers (Problematic Setup)
We were registering keyed producers like this:
static IServiceCollection AddKeyedProducer(this IServiceCollection services, string producerName)
{
services.AddKeyedTransient<IMessageProducer>(producerName, (serviceProvider, _) =>
{
var producerAccessor = serviceProvider.GetRequiredService<IProducerAccessor>();
var producer = producerAccessor.GetProducer(producerName);
return producer;
});
return services;
}
Then adding the producer like this:
services.AddKeyedProducer(Constants.ProducerNames.ProducerName);
And in the service we injected the producer
public class Service(
[FromKeyedServices(Constants.ProducerNames.ProducerName)]
IMessageProducer producer)
{
public async Task SendAsync(Message message)
{
await producer.ProduceAsync(null, message);
}
}
Observed Problem
With this setup:
- The first
ProduceAsync call would often succeed.
- A subsequent call (sometimes immediately after, sometimes later) would cause the application to terminate.
- The process crashed with:
Assertion failed: (r == 0), function rwlock_rdlock,
file tinycthread_extra.c, line 186.
No managed exception was thrown.
No additional logs were emitted — even with debug logging enabled.
The crash appeared to originate from the native layer (librdkafka).
The behavior was intermittent but reproducible under load or when producing multiple messages in sequence.
What We Changed (Working Setup)
Instead of injecting a keyed IMessageProducer, we changed the pattern to inject IProducerAccessor directly into the service and retrieve the producer explicitly when needed.
public class Service(IProducerAccessor producerAccessor)
{
public async Task SendAsync(Message message)
{
var producer = producerAccessor.GetProducer(Constants.ProducerNames.ProducerName);
await producer.ProduceAsync(null, message);
}
}
After this change:
- The crash no longer occurs.
- Multiple sequential
ProduceAsync calls work as expected.
- No native assertions are triggered.
Expected behavior
Producing multiple messages sequentially using an injected IMessageProducer should:
- Work reliably.
- Not terminate the process.
- Not trigger native assertion failures.
- Surface any failures as managed exceptions or proper logs.
Actual behavior
- First
ProduceAsync call succeeds.
- A subsequent call causes the application to terminate immediately.
- No managed exception is thrown.
- No additional logs are emitted.
- The process crashes with:
Assertion failed: (r == 0), function rwlock_rdlock,
file tinycthread_extra.c, line 186.
The crash appears to originate from a native rwlock inside librdkafka.
KafkaFlow version
4.1.0
Prerequisites
Description
We experienced a critical issue when producing Kafka messages where:
No additional logs were emitted — even with debug logging enabled.
Environment
Steps to reproduce
How We Were Registering Producers (Problematic Setup)
We were registering keyed producers like this:
Then adding the producer like this:
And in the service we injected the producer
Observed Problem
With this setup:
ProduceAsynccall would often succeed.No managed exception was thrown.
No additional logs were emitted — even with debug logging enabled.
The crash appeared to originate from the native layer (librdkafka).
The behavior was intermittent but reproducible under load or when producing multiple messages in sequence.
What We Changed (Working Setup)
Instead of injecting a keyed
IMessageProducer, we changed the pattern to injectIProducerAccessordirectly into the service and retrieve the producer explicitly when needed.After this change:
ProduceAsynccalls work as expected.Expected behavior
Producing multiple messages sequentially using an injected
IMessageProducershould:Actual behavior
ProduceAsynccall succeeds.The crash appears to originate from a native rwlock inside librdkafka.
KafkaFlow version
4.1.0