openhab / openhab-cloud

Cloud companion for openHAB instances
Eclipse Public License 2.0
315 stars 161 forks source link

[WIP] updated disconnection logic and clean up unused noise #381

Closed digitaldan closed 2 years ago

digitaldan commented 2 years ago

Signed-off-by: Dan Cunningham dan@digitaldan.com

digitaldan commented 2 years ago

I ended removing a bunch of dead code that has never been used. Also i put a data cap on our notification log as that collection on mongo is uncapped and has grown to over 40gb on production for no good reason.

ssalonen commented 2 years ago

For the record, this potentially resolves a race condition which leads to cloud thinking that client is offline even though it is connected. See https://github.com/openhab/openhab-cloud/issues/134#issuecomment-1120132195 for more info

Quoting from our 1on1 discussion

Only failure scenario that comes to mind is race condition

  1. Client disconnects on node X, code continues to prepare to send “disconnected” notification and store new status to Mongo
  2. Node X hangs a moment
  3. Client reconnects on node Y code continues to prepare to send “connected” notification and store new status to Mongo
  4. Process on node Y commits to Mongo (online status)
  5. Process ok node X commits to Mongo (offline status)

I realized that any false online status will be always cleared by ping/pong. However, there are no mechanism in place to correct false offline status.

This PR utilizes unique IDs for sessions combined with Mongo atomic query/update commands to resolve the possible race conditions

ssalonen commented 2 years ago

@digitaldan how to get this merged?

digitaldan commented 2 years ago

Yeah, i have been procrastinating a little as I need to block off time to do a proper deployment to the general service once we merge. I also then need to remove a few unused (but very large) collections from mongo. I'll probably do that Sunday, probably will post something to the forums later today about the upcoming maintenance.