Refactor database connection handling in web viewer and improve error logging; fix keyword reporting to web viewer

- Simplified database connection management by using context managers to ensure connections are properly closed.
- Enhanced error handling during MQTT client disconnection in packet capture service, logging specific exceptions.
- Updated message handling in MessageHandler to capture command data for web viewer integration, improving response tracking.
This commit is contained in:
agessaman
2026-01-01 12:16:22 -08:00
parent 5ae67bc071
commit 80b6bcceea
3 changed files with 110 additions and 126 deletions
@@ -331,8 +331,12 @@ class PacketCaptureService(BaseServicePlugin):
try:
mqtt_client_info['client'].disconnect()
mqtt_client_info['client'].loop_stop()
except:
pass
except (AttributeError, RuntimeError, OSError) as e:
# Silently ignore expected errors during cleanup (client already disconnected, etc.)
self.logger.debug(f"Error disconnecting MQTT client during cleanup: {e}")
except Exception as e:
# Log unexpected errors but don't fail cleanup
self.logger.warning(f"Unexpected error disconnecting MQTT client: {e}")
# Close output file
if self.output_handle: