Skip to content

Conversation

@X9X0
Copy link
Owner

@X9X0 X9X0 commented Nov 20, 2025

🐛 Fixes
Critical: Server Container Crash on Fresh Pi Image

Root Cause: Missing requests dependency caused ModuleNotFoundError on startup
Fix: Added requests==2.31.0 to server/requirements.txt
Impact: Server containers now start successfully on Pi
Unreliable LabLink Service Startup

Problem: lablink.service used Type=oneshot with no restart policy, insufficient wait times
Fix: Enhanced systemd service configuration in build-pi-image.sh:
Changed to Type=forking for proper container process management
Added Restart=on-failure with 10s exponential backoff
Extended timeouts: 120s start, 30s stop
Improved health checks: waits up to 30s for containers to be healthy
Added Docker daemon readiness check: waits up to 60s before starting
Impact: LabLink automatically recovers from failures and handles boot timing issues
✨ New Features
Comprehensive Pi Diagnostics System

Added integrated diagnostic tooling accessible directly from the LabLink client GUI:

  1. Diagnostic Script (diagnose-pi.sh)

System information (hostname, uptime, Pi model)
Network status (IP addresses, connectivity, DNS)
Docker status and daemon health
LabLink installation verification
Service and container status
Port listener detection
Recent logs analysis
Automated recommendations for common issues
2. Server API (POST /api/diagnostics/pi-diagnostics)

Executes diagnostic script on Pi server
60-second timeout with full output capture
Returns structured results with exit codes
3. Client API (client.run_pi_diagnostics())

90-second timeout for network latency
Clean error handling
4. GUI Integration (Diagnostics Panel)

"Run Pi Diagnostics" button in Diagnostics tab
Beautiful results dialog featuring:
Scrollable monospace output
Copy to clipboard button
Save to timestamped file (e.g., pi-diagnostics-20251120-142530.txt)
Color-coded success/failure status
Clear error messages with troubleshooting hints
🎯 Benefits
✅ No more "Connection Refused" errors on fresh Pi images
✅ Automatic service recovery if containers crash
✅ One-click troubleshooting without SSH access
✅ Streamlined debugging with comprehensive system reports
✅ Easy issue sharing via copy/save functionality
✅ Better resilience to boot timing issues on slower Pi models
📝 Testing
For Existing Pi (with crash issue):

cd /opt/lablink
sudo docker compose down
sudo docker compose build --no-cache
sudo docker compose up -d
lablink-status
For New Pi Images:

Rebuild Pi image using the updated build-pi-image.sh
All fixes automatically included
For GUI Diagnostics:

Connect to Pi server in LabLink client
Navigate to Diagnostics tab
Click "Run Pi Diagnostics"
View/copy/save comprehensive report
🔧 Files Changed
server/requirements.txt - Added requests dependency
build-pi-image.sh - Enhanced systemd service and first-boot script
diagnose-pi.sh - New comprehensive diagnostic script
server/api/diagnostics.py - New Pi diagnostics endpoint
client/api/client.py - New run_pi_diagnostics() method
client/ui/diagnostics_panel.py - GUI integration with results dialog

Problem:
- Client shows "Connection refused" on port 8000 when connecting to fresh Pi
- Docker containers not starting reliably on Pi first boot
- No automatic restart if LabLink service fails
- Insufficient wait time for Docker daemon to be ready

Changes to build-pi-image.sh:

1. Systemd Service Improvements (lablink.service):
   - Changed Type from 'oneshot' to 'forking' for better process management
   - Added Restart=on-failure with 10s backoff for automatic recovery
   - Added TimeoutStartSec=120 and TimeoutStopSec=30 for proper timing
   - Added ExecStartPre to wait 2s for Docker to be fully ready
   - Improved ExecStartPost to wait up to 30s for containers to be healthy
   - Service now properly monitors and restarts containers if they fail

2. First-Boot Script Improvements:
   - Added Docker daemon readiness check (waits up to 60s)
   - Verify Docker is responding before attempting compose up
   - Improved container health check (waits up to 60s with progress updates)
   - Better error logging with container logs on failure
   - Clear error messages with manual recovery instructions

Benefits:
- LabLink will automatically restart if containers crash
- Better handles race conditions during boot
- Provides clear feedback if something fails
- More resilient to timing issues on slower Pi models
- Easier troubleshooting with improved log output

Fixes: Connection refused error on fresh Pi image with main branch
The Pi discovery module (discovery/pi_discovery.py) uses the requests
library but it was not included in server/requirements.txt, causing the
Docker container to crash on startup with:
  ModuleNotFoundError: No module named 'requests'

This fix adds requests==2.31.0 to the requirements to resolve the
dependency issue and allow the server to start properly.

Fixes: Container crash-loop on Pi with 'No module named requests' error
Adds comprehensive Pi diagnostics capability directly from the LabLink client:

Server changes (server/api/diagnostics.py):
- New POST /diagnostics/pi-diagnostics endpoint
- Executes diagnose-pi.sh script on the server
- Returns full diagnostic output with 60s timeout
- Checks /opt/lablink and fallback paths for script

Client API (client/api/client.py):
- New run_pi_diagnostics() method
- 90-second timeout for server execution
- Returns diagnostic output and exit status

Client GUI (client/ui/diagnostics_panel.py):
- New "Run Pi Diagnostics" button in Diagnostics panel
- Shows progress dialog during execution
- Results displayed in scrollable monospace text dialog
- Features:
  * Copy output to clipboard
  * Save output to timestamped file
  * Color-coded success/failure status
  * Clear error handling with troubleshooting hints

Benefits:
- Streamlined troubleshooting without SSH access
- One-click system diagnostics from GUI
- Easy sharing of diagnostic output
- Automated detection of common issues

Usage:
1. Connect to Pi server in LabLink client
2. Go to Diagnostics tab
3. Click "Run Pi Diagnostics"
4. View/copy/save comprehensive system report
Security fixes:
- GHSA-9wx4-h78v-vm56: Fixed cert verification bypass in Session
- GHSA-9hjg-9r4m-mvj7: Fixed .netrc credential leak to third parties

Upgraded from requests 2.31.0 to 2.32.4 (latest secure version)
@X9X0 X9X0 merged commit 77fb608 into main Nov 20, 2025
25 checks passed
@X9X0 X9X0 deleted the claude/debug-client-server-pi-013gro9B5KVA6EY6mD2JLUoL branch November 20, 2025 18:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants