launchdarkly / ld-relay

LaunchDarkly Relay Proxy
Other
111 stars 80 forks source link

feat: replace offline-mode filewatcher with polling [backport from v8] #390

Closed cwaldren-ld closed 5 months ago

cwaldren-ld commented 5 months ago

We've encountered robustness issues with the current offline-mode file-watcher implementation in Docker images that use shared volumes. Additionally, we're seeing intermittent CI failures in the file-watcher tests.

Overall, I believe the complexity introduced by file-watcher isn't worth the payoff. It is supposed to unify all the different operating system methods of notifying that files have changed, but it falls short.

The vast majority of the latency when using offline mode would be downloading the actual archive from LaunchDarkly and the interval between those downloads - which might be minutes/hours/days.

This commit replaces the file-watcher with a simple polling loop. Every interval, it calls stat() and determines if the offline archive needs to be reloaded.

The default interval is 1 second, and the minimum configurable is 100ms. The minimum was chosen to protect the system in case of accidental configuration of an extremely short interval (like 0).

In practice, most users may raise the interval - for example, if they're fetching the archive every hour, there is no need to use a 1 second interval.