`rethinkdblog` output plugin blocks the reactor thread on every `write`, freezing all honeypot sessions
Describe the bug
src/cowrie/output/rethinkdblog.py's Output.write() calls
r.table(self.table).insert(event).run(self.connection) directly
against a rethinkdb connection. The RethinkDB Python driver's default
run() is synchronous and performs blocking network I/O. Since
write() runs directly on the Twisted reactor thread, every logged
event blocks the entire process, freezing every connected honeypot
session for the duration of each RethinkDB round trip. Same root cause
as the identically-shaped bug already reported against redis.py.
To Reproduce Steps to reproduce the behavior:
- Enable the
output_rethinkdblogplugin pointed at a RethinkDB server (or an address that will hang rather than immediately refuse the connection). - Make the RethinkDB server slow or unresponsive.
- Trigger any logged event and observe that every other connected honeypot session stops responding until the RethinkDB call returns or times out.
Expected behavior
A slow or unreachable RethinkDB server should not freeze unrelated
honeypot sessions; the blocking insert().run() call 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.
write()reuses a single mutable RethinkDB connection object across every call; concurrent queries against the same connection from multiple threads are not guaranteed safe by the driver. 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.- This file also has a second, unrelated bug (incorrect UTC/local time
handling in
iso8601_to_timestamp()); I'll report it separately. - Patched file:
src/cowrie/output/rethinkdblog.py(Output.start(): creates and starts the dedicated thread pool;Output.write(): now defers the (renamed)_insert()body to that pool viatwisted.internet.threads.deferToThreadPoolinstead of running it directly;Output.stop(): stops the thread pool too).
Source: cowrie/cowrie