Skip to content

fix: reconnect attempts after successful pool fill - #140

Merged
AlexStocks merged 4 commits into
apache:masterfrom
222twotwotwo:fix-disable-reconnect-after-enough-intermittent-failures
Aug 13, 2026
Merged

AlexStocks merged 4 commits into
apache:masterfrom
222twotwotwo:fix-disable-reconnect-after-enough-intermittent-failures

Conversation

@222twotwotwo

@222twotwotwo 222twotwotwo commented Aug 7, 2026 •

Copy link
Copy Markdown

What this PR does:

Fixes reconnect attempt accounting so successful pool fills no longer consume the reconnect failure budget. connect() now reports whether it actually added a session, and reConnect() only increments reconnectAttempts when no session was added.

Also adds regression coverage for:

  • bounded reconnect exit when the target remains unreachable
  • successful connection pool fills with ConnectionNumber > ReconnectAttempts

Which issue(s) this PR fixes:

Fixes #132

Special notes for your reviewer:

This keeps the upstream-style single-attempt dial behavior, while making retry accounting track consecutive failures rather than successful pool-fill progress.

Validated with:

go test ./...
go vet ./...
git diff --check

Does this PR introduce a user-facing change?:

NONE

@222twotwotwo 222twotwotwo changed the title fix: reset reconnect attempts after successful pool fill fix: reconnect attempts after successful pool fill Aug 7, 2026
@AlexStocks
AlexStocks requested a lite review from Copilot August 8, 2026 06:42

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes reconnect attempt accounting so that successful connection pool fills do not consume the reconnect failure budget, and adds regression tests covering bounded reconnect exit and successful pool fills when ConnectionNumber > ReconnectAttempts.

Changes:

  • Refactors connect() to return whether it successfully added a session, and updates reConnect() to count only consecutive failures (with capped backoff).
  • Simplifies dial paths (TCP/UDP/WS/WSS) to single-attempt behavior and propagates TLS-config builder failures cleanly.
  • Adds regression tests for max-attempt reconnect exit and for successful multi-session pool fills with a small reconnect budget.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
client.go Updates dial/connect/reconnect logic to track reconnect attempts by consecutive failures and to reset on successful session adds.
client_test.go Adds regression tests validating reconnect attempt bounds and successful connection pool fills.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread client.go Outdated
Comment on lines +397 to +400
c.Unlock()
ss.SetAttribute(sessionClientKey, c)
ss.SetAttribute(ignoreReconnectKey, false)
break
return true

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已修复并补充测试

Comment thread client_test.go
}
clt.RunEventLoop(cb)

assert.Equal(t, connPoolSize, msgHandler.SessionNumber())

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] 让测试真正覆盖成功后重置连续失败计数

这个用例只有连续成功建满连接池。删除 client.go 中的 reconnectAttempts = 0 后,我在 exact Head mutant 上执行 go test -count=50 . -run "TestTCPClientReconnect(StopsAfterMaxAttempts|AttemptsIgnoreSuccessfulPoolFills)$" 仍全部通过,因此它没有覆盖本 PR 的关键行为。错误实现会把成功前的失败次数带到后续重连,导致‘失败 -> 成功 -> 再次失败’时提前耗尽上限并留下未填满的连接池。请把建连结果做成可控序列,至少覆盖失败、成功、再次失败和再次成功;断言每次成功都会重置连续失败计数,并确认删除重置语句后测试稳定失败。

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

收到,已进行改动

@222twotwotwo
222twotwotwo force-pushed the fix-disable-reconnect-after-enough-intermittent-failures branch from ee1973f to cd64a48 Compare August 9, 2026 10:17
Comment thread client.go
// gorilla/websocket/conn.go:(Conn)Close also invoke net.Conn.Close()
_ = ss.Conn().Close()
}
return false

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] 这个 return false 只有 dial 失败并跳出 connect() 内部循环后才会执行。只要 dial 成功而 c.newSession(ss) 持续返回错误,当前实现就会关闭连接后立即在 connect() 内再次 dial,永远不会回到 reConnect() 增加 reconnectAttempts 或执行 backoff。当前 Head 的定向测试配置最大尝试次数为 2,但 RunEventLoop 超过 500ms 仍未返回。请让 connect() 一次只完成一次 dial/初始化尝试;newSession 失败时关闭 session 并返回 false,由外层统一计数和退避,同时补“dial 成功、newSession 连续失败”的回归测试。

@222twotwotwo 222twotwotwo Aug 12, 2026 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

收到,已将connect()从内部循环改为单次尝试,并补充测试

@AlexStocks
AlexStocks merged commit 5e9c87f into apache:master Aug 13, 2026
2 checks passed
222twotwotwo added a commit to 222twotwotwo/dubbo-getty that referenced this pull request Sep 5, 2026
Address CodeRabbit review on PR apache#140:
- TestReconnectTriggerDuringBackoffIsCoalesced: keep the reconnect
  interval far above the 50ms assertion window so CI scheduling
  delay cannot start attempt 2 inside the window; Close() cancels
  the backoff so the test stays fast.
- TestTCPClientOnOpenCloseKeepsPoolAtConfiguredSize: inspect ssMap
  before calling sessionNum(), which prunes closed sessions and
  would otherwise hide them from the closed-session count.
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.

[BUG] transport review findings: shutdown deadlock, nil-listener panic, websocket leak, and reconnect lifecycle issues

3 participants