Repository navigation
fix(eew): detect and recover from silently dropped live feeds - #614
Merged
Merged
Conversation
Codecov Report❌ Patch coverage is ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This was referenced Oct 15, 2026
lowrt
previously approved these changes
Oct 16, 2026
lowrt
left a comment
Contributor
There was a problem hiding this comment.
已測
開著地震速報頁,Wi-Fi ↔ 行動網路來回切換,確認幾秒內重新連上。
開關飛航模式一次。
約2.5~5秒重新連上
Platform: all Fix(zh-Hant): 修正網路切換後地震速報連線已中斷卻仍顯示連線正常,現在會自動發現並重新連線 Fix(en-US): the earthquake alert feed no longer shows as connected after a network switch silently cut it off; it now notices and reconnects
Platform: all Optimization(zh-Hant): 伺服器中斷後各裝置錯開時間重新連線,恢復時不再一起湧入,速報連線更快恢復 Optimization(en-US): devices now reconnect at staggered times after a server outage instead of all at once, so the alert feed recovers faster
Platform: all Fix(zh-Hant): 切換 Wi-Fi 與行動網路或重新連上網路後,地震速報與即時測站連線會立即重新建立,不必等到逾時 Fix(en-US): switching between Wi-Fi and mobile data, or coming back online, now reconnects the earthquake alert and station feeds at once instead of waiting for a timeout
Platform: all Fix(zh-Hant): 速報即時連線中斷時改為每 10 秒查詢一次,期間發布的速報仍會出現在地震速報頁,並標示資料可能已過期 Fix(en-US): while the live alert connection is down, the app checks for alerts every 10 seconds, so one issued meanwhile still appears on the early warning page, marked as possibly out of date
whes1015
force-pushed
the
fix/realtime-feed-liveness
branch
from
October 16, 2026 18:19
2c1419e to
b084e0d
Compare
This was referenced Oct 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
這個 PR 做了什麼
地震速報(EEW)和即時測站(RTS)的 SSE 連線,在網路切換或 NAT 逾時後可能變成「半斷」:socket 沒有關閉、沒有錯誤,只是再也收不到資料。原本的設計把「連線開著」當作存活,所以這時畫面會一直顯示「已連線、無警報」,下一則速報卻永遠送不進來。這個 PR 讓 app 能發現這種狀況並重新連線;連線中斷期間,改用 API 輪詢補上速報。
改動內容
正式程式碼
823c7855偵測半斷連線sse_client.dart:伺服器每 60 秒送的: ping原本被直接丟掉,現在改成交給上層,當作「連線還活著」的證據,但不會被當成資料解析。sse_realtime_source.dart:記錄最後一次收到任何位元組的時間。超過sseSilenceLimit(132 秒 = 2.2 × 60 秒 ping)沒收到東西,就回報錯誤並重連。為什麼是 2.2 倍:LB hub 只在等待結束時檢查要不要送 ping,健康但安靜的連線兩個位元組之間最長可能接近兩個間隔。api_client.dart:SSE 請求原本把receiveTimeout設為 0(關閉),改成同一個上限。這樣 app 在inactive(例如拉下通知欄)時,半斷的連線也會被換掉。rts_realtime_source.dart:RTS 睡眠模式下原本「沒資料就是平靜」,現在超過上限的沉默不再當作平靜。0cb0fc2e重連加入 ±50% 隨機抖動:原本固定 1/2/3 秒。伺服器重啟時,所有裝置不會在同一瞬間湧入。dca90459網路一變就重連NetworkChannel.kt(Android)和NetworkPlugin.swift(iOS)兩個原生 channel,回報網路變化。沒有加connectivity_plus,照 repo 偏好原生實作的原則。Android 新增ACCESS_NETWORK_STATE權限。RealtimeService分送給各個 source:網路真的換了(Wi-Fi ↔ 行動網路、離線 → 上線)就丟掉舊 socket、重設退避,隨機等 1–2 秒後重連。inactive時保留 socket 的既有行為不變。b084e0d2連線中斷時輪詢速報getEewRealtime,走同一套解碼和 JMA/只看 CWA 的過濾。stale,不會是live:10 秒一次的快照做不到live承諾的即時,所以速報會顯示在地震速報頁,並帶「資料可能已過期」的提示。ARCHITECTURE.md § Realtime feeds跟著每個 commit 更新,因為那份文件就是這些行為的契約。測試
RealtimeService分送、輪詢回退,以及 staleness 分類在回退資料下的行為。相關 issue
沒有對應的 issue,是比對各端連線處理時發現的。
怎麼驗
tool/commit.sh --push通過:analyze、codegen、全部 Dart 測試。tool/dev/test_ios.sh通過。wifi:en0),這種情況仍要等沉默上限才會發現。伺服器心跳維持 60 秒,不調整。 一般 TCP 斷線會直接觸發錯誤並重連,這個 132 秒的上限只是給「沒有 FIN、沒有 RST」那種半斷連線的保底,不需要更短的心跳。
檢查清單
tool/check/commits.sh origin/main..HEAD通過tool/commit.sh --push)AppLocalizations(沒有新增字串,沿用既有的過期提示)