Files
archived-rttys/server.go
Jianhui Zhao 1d24c36d43 prevent accidental removal of existing device on duplicate ID conflict
When a new device connection is established, it creates a Device struct and
checks for ID conflicts. If a conflict exists, the new device connection
closes and triggers DelDevice via its defer statement. The original
implementation used LoadAndDelete which removed any device with the given ID,
causing the existing device to be incorrectly removed.

This changes the deletion logic to use CompareAndDelete, which verifies
both the device ID and the specific device instance. Now when a duplicate
connection closes, only the new (unregistered) device is attempted for removal,
preserving the existing device in the registry.

This ensures legitimate devices remain connected when duplicate connection
attempts occur.

Signed-off-by: Jianhui Zhao <zhaojh329@gmail.com>
2025-08-14 12:17:11 +08:00

2.1 KiB