- Add socket import for proper resource handling
- Force garbage collection on thread exit to clean up resources
- Wrap thread exit in finally block to ensure cleanup happens
- Fixes ConnectionResetError exceptions on Windows when background refresh finishes