TheThingsNetwork / lorawan-stack

The Things Stack, an Open Source LoRaWAN Network Server
https://www.thethingsindustries.com/stack/
Apache License 2.0
975 stars 306 forks source link

New connections overwrite existing connections #1987

Closed johanstokking closed 4 years ago

johanstokking commented 4 years ago

Summary

New connections overwrite existing connections

Steps to Reproduce

  1. Connect gateway over UDP
  2. Connect another gateway with the same EUI
  3. Disconnect any of the gateways
  4. The gateway by UID gets removed from a map which is used for downlink, so downlink is broken

What do you see now?

Gateway Server maps the connections by UID and removes entries on gateway disconnects, while there may be another gateway connected. This can be due to an unclean disconnect or anything else. References https://github.com/TheThingsNetwork/lorawan-stack/issues/1729 and probably #1730 (and probably https://github.com/TheThingsIndustries/lorawan-stack/issues/1735).

What do you want to see instead?

Actively disconnect existing connections when a gateway connects.

How do you propose to implement this?

https://github.com/TheThingsNetwork/lorawan-stack/blob/master/pkg/gatewayserver/gatewayserver.go#L415

Here we probably want a loop that does a LoadOrStore(), and as long as there's a connection loaded, disconnect it and wait for that connection. You can close a signaling channel here: https://github.com/TheThingsNetwork/lorawan-stack/blob/master/pkg/gatewayserver/gatewayserver.go#L476

That waiting is necessary to clean up all upstream handling of the old connection and ensure that the Delete() from the map is the concerning connection, and not already the new connection, still breaking downlink.

Can you do this yourself and submit a Pull Request?

Can review, can do

johanstokking commented 4 years ago

cc @rvolosatovs @KrishnaIyer