Skip to content

feat: configurable whatsmeow keepalive interval via env#3

Open
chengkangzai wants to merge 1 commit into
devlikeapro:masterfrom
chengkangzai:feat/keepalive-interval-env
Open

feat: configurable whatsmeow keepalive interval via env#3
chengkangzai wants to merge 1 commit into
devlikeapro:masterfrom
chengkangzai:feat/keepalive-interval-env

Conversation

@chengkangzai

Copy link
Copy Markdown

Problem

Running the GOWS engine with sessions behind residential/rotating proxies, sessions flap STARTINGWORKING continuously on Keepalive timed out, and real operations fail during the flap.

whatsmeow pings the websocket on a random interval in [KeepAliveIntervalMin, KeepAliveIntervalMax) = 20-30s (keepalive.go). Many residential/rotating proxy exits reap an idle CONNECT tunnel sooner (~10-15s in our measurements), so the ping lands on an already-dead socket every time → timeout → reconnect → repeat. It is not a ban and not a creds problem — the session re-authenticates every cycle.

KeepAliveIntervalMin / KeepAliveIntervalMax are exported package-level vars, so a consumer can lower them to beat the reap — but there is currently no way to set them from WAHA/GOWS.

Change

Add two env vars (following the existing env.Parse / getClientConfig() pattern):

WAHA_GOWS_KEEPALIVE_INTERVAL_MIN_SEC=8
WAHA_GOWS_KEEPALIVE_INTERVAL_MAX_SEC=12
  • Both in seconds; 0/unset leaves whatsmeow's default untouched.
  • Applied once at startup in main(), right after the client-config block.
  • max is clamped to strictly greater than min (whatsmeow does rand.Int64N(max-min)+min, which panics if max <= min); if invalid it's adjusted to min + 10s with a warning.

Files: src/env.go (config struct + parser), src/main.go (apply + guard), src/env_test.go (parse tests), docs/env.md (docs).

Testing

  • gofmt clean.
  • The exact assignments (whatsmeow.KeepAliveIntervalMin/Max = ...) compile and run against the pinned devlikeapro/whatsmeow fork.
  • Env-parse tests added (TestKeepAliveConfig_NotSet, TestKeepAliveConfig_Values).
  • Full go build ./... needs the generated proto stubs + libvips, which CI provides — please run CI to confirm the complete build.

Fixes the root cause described in devlikeapro/waha#2167.

whatsmeow pings the websocket on a random interval in [min, max)
(default 20-30s). Behind proxies that reap idle tunnels sooner, the
ping lands on a dead socket every time, producing constant
"Keepalive timed out" reconnect loops (session flapping).

Add WAHA_GOWS_KEEPALIVE_INTERVAL_MIN_SEC / _MAX_SEC to override the
interval and keep the tunnel warm. Unset (0) leaves the whatsmeow
default. max is clamped to > min to avoid a rand panic at ping time.

Refs devlikeapro/waha#2167
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