#40484·cowrie

`socketlog` 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/socketlog.py's Output.write() calls self.sock.sendall(...) directly on a plain blocking socket.socket() (not any Twisted-async networking primitive), and Output.start()'s self.sock.connect(...) is equally blocking. Since write() runs directly on the Twisted reactor thread, every logged event blocks the entire process for up to the configured timeout setting, freezing every connected honeypot session, if the remote log collector is slow to accept data. Same root cause as the identically-shaped bug already reported against redis.py.

To Reproduce Steps to reproduce the behavior:

  1. Enable the output_socketlog plugin pointed at a TCP listener that accepts the connection but is slow to read from the socket (so sendall() blocks waiting for buffer space).
  2. Trigger any logged event and observe that every other connected honeypot session stops responding until sendall() returns or the configured timeout elapses.

Expected behavior A slow remote log collector should not freeze unrelated honeypot sessions; the blocking socket I/O 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.
  • Unlike most of the other output plugins in this batch, this one reuses a single mutable socket object across every write. Moving sendall() to the reactor's default multi-worker deferToThread pool would let concurrent writes from different worker threads interleave partial sendall() calls on the same socket, corrupting the byte stream the remote collector sees. The fix instead uses a dedicated single-worker twisted.python.threadpool.ThreadPool (started in start(), stopped in stop()), which keeps connect()/sendall() off the reactor thread while still running them strictly one at a time, in submission order.
  • Patched file: src/cowrie/output/socketlog.py (Output.start(): creates and starts the dedicated thread pool once, then connects via a new _connect() helper; Output.write(): now defers the (renamed) _send() body to that pool via twisted.internet.threads.deferToThreadPool; the existing broken-pipe reconnect logic now calls _connect() instead of re-running all of start(), so reconnecting no longer recreates the thread pool; Output.stop(): stops the thread pool too).

socketlog.py