zhulik / aiotractive

Asynchronous Python client for the Tractive REST API
MIT License
20 stars 6 forks source link

Improve reliability (keep alive timeout issue) #19

Closed oandrew closed 10 months ago

oandrew commented 10 months ago

I was getting frequent Tractive is not available. Internet connection is down? Sleeping 10 seconds and retrying errors in my home assistant.

Turns out, Tractive api occasionally "restarts" the stream by sending a new "handshake" message. In such scenarios, the duration between keep-alive messages is ~10s which is higher than current 7s. Logs:

2023-08-21 23:30:08.103680
b'{"message":"keep-alive", ...}\n'

2023-08-21 23:30:11.142572
b'{"message":"tracker_status", ...}\n'

2023-08-21 23:30:13.833765
b'{"message":"handshake", ...}\n'

2023-08-21 23:30:14.025513
b'{"message":"tracker_status", ...}\n'

2023-08-21 23:30:14.177498
b'{"message":"activity_update", ...}\n'

2023-08-21 23:30:14.223398
b'{"message":"wellness_overview", ...}\n'

2023-08-21 23:30:16.379405 <<CURRENT LOGIC TIMES OUT HERE>>

2023-08-21 23:30:16.703810
b'{"message":"tracker_status", ...}\n'

2023-08-21 23:30:18.833432
b'{"message":"keep-alive", ...}\n'
zhulik commented 10 months ago

@oandrew version 0.5.6 with your fix has been released. Thanks again!