fix: Resolve Pi server connection issues and add comprehensive diagnostics system #89
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
🐛 Critical Fixes
Server Container Crash on Fresh Pi Image
Root Cause: Missing requests dependency caused ModuleNotFoundError on startup
Fix: Added requests==2.32.4 to server/requirements.txt with security patches
Impact: Server containers now start successfully without crash-looping
Unreliable LabLink Service Startup
Problem: lablink.service used Type=oneshot with no restart policy and 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
Diagnostic Script Not Accessible in Container
Problem: diagnose-pi.sh existed on host but not inside Docker container
Fix: Updated Dockerfile.server to copy script and install required tools (sudo, iproute2, iputils-ping, procps)
Impact: Pi diagnostics endpoint now works correctly
✨ New Features
Comprehensive Pi Diagnostics System
Integrated diagnostic tooling accessible directly from the LabLink client GUI:
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
5. Version Verification Script (verify-pi-code.sh)
Verify what code version is running on Pi
Check if endpoints exist in deployed code
Validate dependencies in containers
Useful for troubleshooting version mismatches
🎯 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
✅ Version verification to diagnose deployment issues
📝 Usage
For Existing Pi (to apply fixes):
cd /opt/lablink
sudo git pull origin main
sudo docker compose down
sudo docker compose build --no-cache
sudo docker compose up -d
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==2.32.4 with security fixes
build-pi-image.sh - Enhanced systemd service and first-boot script
diagnose-pi.sh - New comprehensive diagnostic script
verify-pi-code.sh - New version verification 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
docker/Dockerfile.server - Copy diagnostic script and install required tools
🔒 Security
Upgraded requests from 2.31.0 to 2.32.4
Fixes GHSA-9wx4-h78v-vm56: Certificate verification bypass
Fixes GHSA-9hjg-9r4m-mvj7: .netrc credential leak