feat: configurable whatsmeow keepalive interval via env#3
Open
chengkangzai wants to merge 1 commit into
Open
Conversation
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
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.
Problem
Running the GOWS engine with sessions behind residential/rotating proxies, sessions flap
STARTING↔WORKINGcontinuously onKeepalive 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/KeepAliveIntervalMaxare exported package-levelvars, 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):0/unset leaves whatsmeow's default untouched.main(), right after the client-config block.maxis clamped to strictly greater thanmin(whatsmeow doesrand.Int64N(max-min)+min, which panics ifmax <= min); if invalid it's adjusted tomin + 10swith 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
gofmtclean.whatsmeow.KeepAliveIntervalMin/Max = ...) compile and run against the pinneddevlikeapro/whatsmeowfork.TestKeepAliveConfig_NotSet,TestKeepAliveConfig_Values).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.