Skip to content

fix: use MESH_HOST_HEARTBEAT_TTL_SECONDS environment variable#37

Merged
takaokouji merged 2 commits intomainfrom
fix/heartbeat-ttl-env-vars
Jan 4, 2026
Merged

fix: use MESH_HOST_HEARTBEAT_TTL_SECONDS environment variable#37
takaokouji merged 2 commits intomainfrom
fix/heartbeat-ttl-env-vars

Conversation

@takaokouji
Copy link
Contributor

Summary

This PR fixes an issue where the environment variable was ignored in several critical parts of the AppSync resolvers, often falling back to a hardcoded 60-second value. This caused groups to expire prematurely in production where the heartbeat interval is also 60 seconds.

Changes

  • Updated and to use for expiration thresholds.
  • Updated and to set the initial based on the environment variable.
  • Improved data consistency by adding to node status items and filtering expired nodes in and .
  • Synchronized default value (30s) across the codebase.

Verification

  • Ran

mesh-v2@0.1.0 test
jest and
Group
#initialize
有効な属性でグループを作成できる
idがnilの場合はエラーを発生させる
idが空文字の場合はエラーを発生させる
nameが空の場合はエラーを発生させる
host_idがnilの場合はエラーを発生させる
domainが空の場合はエラーを発生させる
domainが256文字を超える場合はエラーを発生させる
created_atが空の場合はエラーを発生させる
#full_id
id@domain形式のfullIdを返す

DynamoDBRepository
#dissolve_group
handles items with multibyte characters correctly
#find_group
handles multibyte characters in keys and attributes

CreateDomainUseCase
#execute
ソースIPをCRC32でハッシュ化して16進数で返す
source_ipがnilの場合は 'none' を使用してハッシュ化する
異なるIPからは異なるドメインが生成される

CreateGroupUseCase
#execute
既存グループが存在しない場合
新しいグループを作成する
グループIDが自動生成される
既存グループが存在する場合
既存グループを返す(冪等性)
同じhostId + domainで複数回呼び出しても同じグループを返す

DissolveGroupUseCase
#execute
正常系
ホストがグループを解散できる
異常系
グループIDが空の場合エラー
ドメインが空の場合エラー
ホストIDが空の場合エラー
グループが存在しない場合エラー
ホストでないノードが解散を試みた場合エラー
べき等性
既に解散されたグループを解散しようとした場合はエラー(グループ不存在)

LeaveGroupUseCase
#execute
ピアがグループから正常に退出する場合
ピアをグループから削除し、データも削除する
成功メッセージを返す
ピアの削除に失敗した場合
失敗の結果を返す
ピアのデータ削除に失敗した場合
失敗の結果を返す
複数のピアが連続して退出する場合
各ピアを独立して処理する

Finished in 0.02825 seconds (files took 0.49589 seconds to load)
30 examples, 0 failures.

  • Verified that JS resolvers correctly parse environment variables with proper fallbacks.

takaokouji and others added 2 commits January 4, 2026 19:51
- Replaced hardcoded 60s with MESH_HOST_HEARTBEAT_TTL_SECONDS in:
  - checkGroupExists (validation threshold)
  - listGroupsByDomain (filtering threshold)
  - createGroup/createGroupIfNotExists (initial TTL)
- Added TTL filtering to listNodesInGroup and listGroupStatuses
- Added TTL to node status items in reportDataByNode
- Updated findNodeMetadata to exclude expired nodes
- Fixed inconsistent heartbeatIntervalSeconds default value in createGroupIfNotExists

Co-Authored-By: Gemini <noreply@google.com>
…time

- MESH_HOST_HEARTBEAT_INTERVAL_SECONDS: 30 -> 60 (production/default)
- MESH_MAX_CONNECTION_TIME_SECONDS: 3000 -> 1500 (production/default)
- MESH_MAX_CONNECTION_TIME_SECONDS: 600 -> 300 (development default in CDK)
- Updated documentation and AppSync resolvers/functions to match these new defaults.

Co-Authored-By: Gemini <noreply@google.com>
@takaokouji takaokouji merged commit 6af9953 into main Jan 4, 2026
3 checks passed
@takaokouji takaokouji deleted the fix/heartbeat-ttl-env-vars branch January 4, 2026 11:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant