#40480·cowrie

`mongodb` output plugin blocks the reactor thread on every `write`, freezing all honeypot sessions

Author: vbontchevCreated Aug 4, 2026Updated Sep 15, 2026

Describe the bug src/cowrie/output/mongodb.py's Output.write() calls find_one(), insert_one(), and update_one() directly against a pymongo collection for every logged event. pymongo's default client is synchronous and performs blocking network I/O. Since write() runs directly on the Twisted reactor thread, every logged event -- across every event type this plugin handles -- blocks the entire process, freezing every connected honeypot session for the duration of each MongoDB round trip (and indefinitely if MongoDB becomes unresponsive). Same root cause as the identically-shaped bug already reported against redis.py; the plugins this codebase already gets right (abuseipdb.py, s3.py) use twisted.internet.threads.deferToThread for exactly this reason.

To Reproduce Steps to reproduce the behavior:

  1. Enable the output_mongodb plugin pointed at a MongoDB server (or an address that will hang rather than immediately refuse the connection).
  2. Make the MongoDB server slow or unresponsive.
  3. Trigger any logged event and observe that every other connected honeypot session stops responding until the MongoDB call returns or times out.

Expected behavior A slow or unreachable MongoDB server should not freeze unrelated honeypot sessions; the blocking MongoDB 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.
  • Several event types in write() do a find_one() lookup and then conditionally update_one() based on the result (e.g. cowrie.client.version, cowrie.session.closed), so calls for the same session must still execute in the order they were submitted -- the reactor's default deferToThread pool runs several worker threads at once and would not guarantee that. The fix instead uses a dedicated single-worker twisted.python.threadpool.ThreadPool (started in start(), stopped in stop()), which keeps every Mongo call off the reactor thread while still running them strictly one at a time, in submission order.
  • Patched file: src/cowrie/output/mongodb.py (Output.start(): creates and starts the dedicated thread pool; Output.write(): now defers the (renamed) _write() body to that pool via twisted.internet.threads.deferToThreadPool instead of running it directly; Output.stop(): stops the thread pool too).

mongodb.py