`socketlog` output plugin blocks the reactor thread on every `write`, freezing all honeypot sessions
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:
- Enable the
output_socketlogplugin pointed at a TCP listener that accepts the connection but is slow to read from the socket (sosendall()blocks waiting for buffer space). - 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-workerdeferToThreadpool would let concurrent writes from different worker threads interleave partialsendall()calls on the same socket, corrupting the byte stream the remote collector sees. The fix instead uses a dedicated single-workertwisted.python.threadpool.ThreadPool(started instart(), stopped instop()), which keepsconnect()/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 viatwisted.internet.threads.deferToThreadPool; the existing broken-pipe reconnect logic now calls_connect()instead of re-running all ofstart(), so reconnecting no longer recreates the thread pool;Output.stop(): stops the thread pool too).
Source: cowrie/cowrie