amplitude / amplitude/experiment-ruby-server

LocalEvaluation + Puma with Worker Processes Requires Reconnect

未關閉
#40 3 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
主要語言
Ruby
星號
3
分支
6
PR 合併指標
30 天內沒有已合併 PR

描述

I set up AmplitudeExperiment with LocalEvaluation in a Puma environment, calling `#start` on the client during Rails initialization.

## Expected Behavior

Each worker process is able to see updates to flag configuration or error is logged alerting you to dead polling thread and potentially stale results.

## Current Behavior

No errors are raised, but the flag configurations are not updated after processes fork and so the flag configurations become stale even though logs show polling behavior happening.

It appears to be that the polling thread is dead when logging from the worker, but the thread is still active in the main process and logging updates (with the logger fix from #38) , which is misleading.

Captured below - we see a fetch of flagVersion 17 but then a few seconds later when inspecting the experiment client we see it is stuck at 16 and poller_thread shows status of `dead` in the inspect:

```

08:26:11 web.1 |
08:26:29 web.1 | [Experiment] Fetch flag configs: [....,"flagKey":"initial_test","flagVersion":17,......]
08:26:33 web.1 | Started GET "/health" for ::1 at 2023-05-22 08:26:33 -0700
08:26:33 web.1 | Processing by HealthController#index as HTML
08:26:33 web.1 | ↳ app/controllers/health_controller.rb:5:in `index'
08:26:34 web.1 | #,
@flags="[{.... \"flagKey\":\"initial_test\",\"flagVersion\":16,...",
@flags_mutex=#,
@logger=#, @formatter=nil, @logdev=#>, @binmode=false, @mon_data=#, @mon_data_owner_object_id=64200>>, @fetcher=#, @logger=#, @formatter=#, @logdev=#, @binmode=false, @mon_data=#, @mon_data_owner_object_id=59680>>>,
@is_running=true,
@poller_thread=#>
```

## Possible Solution

Either documentation to describe how to achieve expected behavior (you must call `#start` after process fork), or better handling of this case to automatically achieve desired behavior (example from Redis client watches a cached @pid variable to detect a fork: https://github.com/redis-rb/redis-client/commit/bec4931c952b6196c76977356238dbaf4f2e1293 )

## Environment
- SDK Version: 1.1.0
- Language Version: 3.1.3

貢獻指南

開啟貢獻指南

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。