Troubleshooting Guide¶
Common issues and solutions for cymongoose applications.
Build Issues¶
"Cython not found"¶
Error:
Solution:
"C compiler not found"¶
Error:
Solutions:
- Linux:
sudo apt-get install build-essential - macOS:
xcode-select --install - Windows: Install Visual Studio with C++ tools
"mongoose.h not found"¶
Error:
Solution:
Mongoose is vendored in thirdparty/mongoose/. Ensure complete clone:
Import Errors¶
"cannot import name 'Manager'"¶
Cause: Extension not built
Solution:
"Symbol not found" on macOS¶
Error:
Solution: Rebuild without cache:
Runtime Issues¶
Ctrl+C Not Working¶
Symptom: Pressing Ctrl+C doesn't stop the server
Cause: With nogil, KeyboardInterrupt may be delayed
Solution: Use signal handlers:
import signal
shutdown_requested = False
def signal_handler(sig, frame):
global shutdown_requested
shutdown_requested = True
signal.signal(signal.SIGINT, signal_handler)
while not shutdown_requested:
manager.poll(100)
See shutdown for details.
HTTP Server Not Responding¶
Symptom: Requests timeout or no response
Causes & Solutions:
-
Missing
http=Trueflag: -
Handler not calling
reply(): -
Firewall blocking port:
Connections Not Closing¶
Symptom: Connections remain open after sending response
Cause: Using conn.close() instead of conn.drain()
Solution:
# Bad
conn.reply(200, b"OK")
conn.close() # May lose data
# Good
conn.reply(200, b"OK")
conn.drain() # Graceful close
Performance Issues¶
Low Throughput¶
Symptom: Lower req/sec than expected (< 30k req/sec)
Checks:
-
Verify nogil is enabled:
If not, rebuild:
-
Check poll timeout:
-
Profile handler:
High CPU Usage¶
Symptom: 100% CPU when idle
Cause: Zero poll timeout (busy loop)
Solution:
Memory Leaks¶
Symptom: Memory usage grows over time
Causes:
-
Not removing closed connections from lists:
-
Holding Connection references:
WebSocket Issues¶
"Upgrade failed"¶
Cause: Not using http=True flag
Solution:
"Connection closed immediately"¶
Cause: Calling conn.drain() or conn.close() after ws_upgrade()
Solution:
def handler(conn, ev, data):
if ev == MG_EV_HTTP_MSG and data.uri == "/ws":
conn.ws_upgrade(data)
# DON'T call drain() or close() here!
elif ev == MG_EV_WS_MSG:
# Now you can send/receive
conn.ws_send("Hello!")
MQTT Issues¶
"Connection refused"¶
Causes:
- Broker not running
- Wrong port (1883 for MQTT, 8883 for MQTTS)
- Firewall blocking connection
Solution: Test with mosquitto_sub:
"Not receiving messages"¶
Cause: Not subscribing after connection
Solution:
def handler(conn, ev, data):
if ev == MG_EV_MQTT_OPEN:
# Subscribe AFTER connection
conn.mqtt_sub("sensors/#", qos=1)
TLS Issues¶
"Certificate verification failed"¶
Causes:
- CA bundle doesn't include root certificate
- Certificate expired
- Hostname mismatch
Solutions:
# 1. Check expiry
# openssl x509 -in cert.pem -noout -enddate
# 2. Verify hostname
opts = TlsOpts(ca=ca, name="exact.hostname.com")
# 3. For development only (INSECURE!)
opts = TlsOpts(skip_verification=True)
"handshake failure"¶
Cause: Missing certificate or key
Solution:
# Server needs both cert and key
cert = open("server.crt", "rb").read()
key = open("server.key", "rb").read()
opts = TlsOpts(cert=cert, key=key)
conn.tls_init(opts)
Multi-Threading Issues¶
"RuntimeError: Connection has been closed"¶
Cause: Passing Connection object to thread
Solution: Pass connection ID:
"Wakeup not working"¶
Cause: Forgot to enable wakeup support
Solution:
Getting Help¶
- Check logs: Enable verbose logging
- Search issues: https://github.com/shakfu/cymongoose/issues
- Minimal reproduction: Create smallest example that shows the issue
- System info: Python version, OS, cymongoose version
Reporting Issues:
# Include this info
python --version
uv run python -c "import cymongoose; print(cymongoose.__version__)"
uname -a