fix driver rebinding

This commit is contained in:
2026-02-18 23:12:19 +01:00
parent cc1dfff382
commit 9d10beec9b
4 changed files with 73 additions and 22 deletions
+14 -3
View File
@@ -276,17 +276,28 @@ func (sm *ShareManager) handleReleaseDevice(busID, fromClient string) {
return
}
// Clean up tunnel
// Close the tunnel pipe to signal HandleConnection to stop reading
var tunnelDone <-chan struct{}
if tunnel, ok := sm.tunnels[share.tunnelID]; ok {
tunnel.inPipe.Close()
tunnelDone = tunnel.done
delete(sm.tunnels, share.tunnelID)
}
// Detach device (release interfaces, reconnect kernel driver)
share.server.Detach()
server := share.server
delete(sm.active, busID)
sm.mu.Unlock()
// Wait for HandleConnection goroutine to finish before detaching.
// This ensures no more URBs are being submitted when we detach.
if tunnelDone != nil {
<-tunnelDone
log.Printf("[share] HandleConnection goroutine finished for %s", busID)
}
// Now safe to detach - no more USB/IP protocol processing
server.Detach()
// Notify client
sm.client.SendJSON(&protocol.DeviceReleased{
Type: protocol.MsgDeviceReleased,