`rmq` (RabbitMQ) output plugin blocks the reactor thread on every `write`, freezing all honeypot sessions
Describe the bug
src/cowrie/output/rmq.py's Output._connect() and Output.write()
use pika.BlockingConnection -- a client pika itself names and
documents as synchronous/blocking -- to connect, declare the exchange,
and publish every event via channel.basic_publish(...). Since
write() runs directly on the Twisted reactor thread, every logged
event (including any reconnection attempt) blocks the entire process,
freezing every connected honeypot session for the duration of each
RabbitMQ operation. Same root cause as the identically-shaped bug
already reported against redis.py.
To Reproduce Steps to reproduce the behavior:
- Enable the
output_rmqplugin pointed at a RabbitMQ broker (or an address that will hang rather than immediately refuse the connection). - Make the broker slow or unresponsive.
- Trigger any logged event and observe that every other connected honeypot session stops responding until the RabbitMQ call (connect, exchange declare, or publish) returns or times out.
Expected behavior A slow or unreachable RabbitMQ broker should not freeze unrelated honeypot sessions; the blocking pika calls should run off the reactor thread.
Server (please complete the following information):
- OS: This bug is OS-independent (Twisted reactor architecture, no OS-specific code involved).
- Python: Python 3.14.2
- Twisted: Twisted 26.4.0
Additional context
- Cowrie Mode: Shell (default), any protocol.
pika.BlockingConnectionis explicitly documented by pika as not safe to use from multiple threads concurrently, and this plugin'schannel/connectionobjects are shared across every write. The fix uses a dedicated single-workertwisted.python.threadpool.ThreadPool(started instart(), stopped instop()) instead of the reactor's default multi-worker pool, keeping the connection's use strictly serialized while still off the reactor thread.- Patched file:
src/cowrie/output/rmq.py(Output.start(): creates and starts the dedicated thread pool;Output.write(): now defers the (renamed)_publish()body -- including the existing reconnect-and-retry logic -- to that pool viatwisted.internet.threads.deferToThreadPoolinstead of running it directly;Output.stop(): stops the thread pool too).
Source: cowrie/cowrie