Repository navigation
feat(node): expose client lifecycle events through on and once - #4552
Arham-Begani wants to merge 12 commits into
Conversation
|
This PR is closed because #2396 is not assigned to you. Good first issues are assigned before work starts. Comment on an issue, wait for a maintainer to assign it to you, and then open a PR. See CONTRIBUTING.md. |
|
Hi! I’d like to work on this. I got ahead of myself and opened #4552 before being assigned, which the bot closed. Sorry about that. @dajneem23 offered back in April, so I’m happy to step back if they’re still on it. #4552 adds typed on/once to Client for connecting, connected, error and end, as T1B0 and spetz asked for on #4061. end fires once after destroy(), and error is only re-emitted when someone listens. It includes unit tests and an e2e test. A few questions before it goes further:
If the approach looks fine, could you assign me? I’ll reopen or open a new PR from the same branch. |
|
Re "Is it OK to also add off/removeListener" - yep, if they are needed, or anything else, you should add them. Re 3 and 4, I'd make them separate issues. |
Thanks @justinmclean! off/removeListener are already in this PR. I’ll open separate issues for 3 and 4, and fold disconnected into the eviction one since T1B0 suggested them together. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #4552 +/- ##
============================================
- Coverage 75.98% 74.53% -1.45%
+ Complexity 4357 4319 -38
============================================
Files 1558 1497 -61
Lines 248509 228664 -19845
Branches 177088 158806 -18282
============================================
- Hits 188820 170440 -18380
+ Misses 53689 52938 -751
+ Partials 6000 5286 -714
🚀 New features to boost your workflow:
|
|
/skill team-review-slim |
There was a problem hiding this comment.
Summary: The new lifecycle events land on the pooled Client only, and a leader move that races destroy() can leave a dialing socket open and report connected after end, which the new contract forbids. A low-confidence concern about generic-pool teardown stayed out, because the library source is not in this checkout to prove it.
Counts: critical 0, warning 3, nit 2, simplification 0
This review was generated by Claude Code 2.1.284 on deepseek-flash[1m]. Review the output before you act on it.
|
/ready |
|
@justinmclean Could you clarify the remaining issue-ownership requirement? This PR is assigned to Arham-Begani, but linked issue #2396 is still unassigned. If the issue itself must also be assigned under CONTRIBUTING, could you assign it, or confirm whether the existing PR assignment is sufficient? The review findings were addressed in This ownership-status follow-up was prepared with OpenAI Codex assistance. |
|
@Arham-Begani i assigned #2396 to you. also i merged #4561 which introduced conflicts here. could you please rebase? |
Client gave applications no way to observe its connection: only the internal CommandResponseStream is an EventEmitter. Add typed on, once, off and removeListener to Client, backed by the pooled connection, for four events: - connecting: once per dial. Each dial gets its own socket, so the announcement is made once per installed socket, deferred one tick so the constructor's first dial reaches listeners attached after it. - connected: the dialed socket is ready (TCP connect or TLS handshake), before login. - error: every error the connection reports. Re-emitted only when a listener exists, because EventEmitter throws on an unheard 'error' and these errors used to reach callers only through failed commands. - end: once, after destroy() closes the socket, so no lifecycle event can follow it. destroy() now resolves after 'end'. The RawClient type is unchanged, so custom RawClient implementations passed to SimpleClient still type-check. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01KqEXKVMqfFH6hmLUyQvjdS
|
The requested rebase is now pushed at Review also caught and fixed deliberate login/logout teardown appearing as public errors, the raw factory's shutdown return type, and compatibility with custom socket-returning destructors. Regression tests cover all three. Exact-source Ubuntu validation passed:
Local Windows build, direct ESLint and all 14 focused regressions also passed. The PR description records the platform limitations and distinguishes this hosted validation from upstream PR CI. New-head upstream checks still require separate verification. GitHub reports the new head as mergeable. Its upstream Pre-merge and PR Title workflows currently report The contributor supplied the rationale in the PR and personally confirmed review and understanding of the final changes. Claude Code assisted with the original implementation; OpenAI Codex assisted with the rebase, corrections, tests and this update. |
Adapt the earlier redirect/shutdown and wrapper fixes to the replica-link architecture introduced by apache#4561. Keep immediate request cancellation and wait for every physical socket close before one final end event. Refuse new links after destruction, retain listener removal, and await custom raw-client destruction through SimpleClient. SingleClient now inherits Client's events. Separate link diagnostics from the raw stream's special error event so internal events.once recovery waits are not rejected by an expected replica failure. Add focused wrapper and routing/destruction regression coverage and update the lazy first-dial and all-replica event documentation. Preserve the original contribution's AI attribution below. OpenAI Codex ported the feature and tests to the new architecture and prepared this rebase. Local validation and environment limitations are recorded separately; this commit does not attest to human review or claim the PR is ready. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01KqEXKVMqfFH6hmLUyQvjdS AI-Assistance: OpenAI Codex
Do not forward deliberate link teardown as a public connection error. Expose the raw-client shutdown promise while accepting synchronous injected clients. Cover login, relogin, logout and factory shutdown completion with regression tests. AI-Assistance: OpenAI Codex
Keep the void callback branch for existing RawClient implementations whose destructor returns a value, while allowing asynchronous shutdown. Add a compile and runtime regression for a custom destructor returning Socket. AI-Assistance: OpenAI Codex
b79775b to
fc31fa2
Compare
|
@hubcio, the requested rebase is now at Pre-merge and PR Title currently report This follow-up was prepared with AI assistance. |
|
Thanks for enabling CI. Upstream Pre-merge now passes on @hubcio, could you take another look when convenient? The requested rebase and review corrections are complete, and there are no unresolved inline threads. GitHub reports the branch as mergeable but behind master; following CONTRIBUTING.md, I'll leave the final branch update to a maintainer unless a conflict appears or you request another rebase. This status update was prepared with AI assistance. |
|
@T1B0 could you please check? |
Keep raw destroy synchronous, settle socket closures before scheduling end, and emit one connecting event until a dial succeeds. Document getClient event availability and cover listener exception semantics and command retry recovery. AI-Assistance: OpenAI Codex
Observe end from construction so facade destruction completes when callers already closed the public raw client. Cover the public provider path and document wrapped command errors. AI-Assistance: OpenAI Codex
|
The four review corrections are pushed at Separate exact-source Ubuntu validation passed 579 unit tests on each of Node 23/24, lint/build, all applicable hooks and the real-server TCP/TLS/BDD suites. The updated PR description records local Windows results and limitations as well. These results do not replace upstream CI. This update was prepared with AI assistance. |
|
Thanks for enabling CI. Upstream Pre-merge now passes on The four requested corrections have individual replies and regression coverage. This head is ready for re-review; the branch is mergeable, so I have left the final synchronization to a maintainer per CONTRIBUTING.md. /request-review @T1B0 This status update was prepared with AI assistance. |
Resolve the reported merge conflicts without rewriting branch history. Keep upstream connection-error classification and sign-in state while preserving lifecycle events and socket-close completion. Adapt two lifecycle tests to the upstream cancellation error and explicit bootstrap retry budget. All 715 SDK unit tests and 24 example unit tests pass on Node 24. Build, protocol mirror, lint, and all nine applicable prek hooks pass. Co-authored-by: OpenAI Codex <[email protected]>
|
we'll merge this PR next week. right now we're merging critical VSR fixes. |
|
Thanks for the scheduling update. Two final lifecycle corrections are pushed at
Validation of this exact source passed 717 unit tests on each of Node 23/24, lint/build, all nine applicable unmodified hooks, 82 TCP tests, 17 TLS tests and 16 BDD scenarios / 114 steps. Windows build, protocol mirror, direct ESLint and 18 focused lifecycle tests also passed. The PR description now records this source and separates these results from upstream CI. Could an authorized maintainer approve the fresh Pre-merge and PR Title runs when ready? Both report This update was prepared with AI assistance, as disclosed in the PR. |
|
Current-head upstream CI is now green at The reviewed source is unchanged. This is ready for re-review when the VSR queue permits; no further CI authorization request is needed for this head. This update was prepared with AI assistance. |
Upstream added operation constants and raw readiness groups beside the lifecycle changes. Preserve both interfaces while resolving the two textual merge conflicts without rewriting the published branch history. Prepared with OpenAI Codex assistance.
|
The two merge conflicts are resolved in Exact-source Ubuntu validation passed all 952 unit tests on both Node 24.22.1 and 26.13.0, canonical lint/build, and all nine applicable unmodified Could an authorized maintainer approve the new Pre-merge and PR Title runs? Both report This update was prepared with AI assistance. |
hubcio
left a comment
There was a problem hiding this comment.
please address the issues below.
A server eviction reaches the client from inside the link's onData handler, which fails the link and re-emits its error and eviction events synchronously. A public eviction listener that threw was taken for a transport failure, and a throwing connectionError listener hit the second, guarded fail() and was dropped without a trace. Public listeners now run on the next tick, like connected already does, so their exceptions surface as ordinary uncaught EventEmitter errors. The client lifetime guard is checked both when the link reports and when the listener runs, so no event follows destroy().
3b7d8af to
2aa5fb3
Compare
|
@hubcio that was the last open thread on my side. Could you take another look? |
|
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. If you need a review, please ensure CI is green and the PR is rebased on the latest master. Don't hesitate to ping the maintainers - either Thank you for your contribution! |
|
/ready |
The contributor branch used the localhost fixture that expired on November 17. Include upstream apache#4745 so the Node TLS tests can validate the lifecycle changes using a current certificate.
Exercise both socket data listener orderings so an eviction racing with destroy cannot escape after shutdown begins. The tests fail when the two eviction lifetime guards are removed. Co-authored-by: Codex <[email protected]>
Which issue does this PR address?
Closes #2396, assigned to Arham-Begani. This updates the existing contribution after the requested rebase following #4561.
Rationale
Contributor-supplied rationale:
What changed?
ClientandSingleClientexpose typed, chainableon,once,offandremoveListenermethods forconnecting,connected,errorandend. Lazy connections, replica routing and session recovery remain supported.endafter all sockets close. Raw destruction stays synchronous; the high-level client returns a shared completion promise, including after direct raw-client closure.connectingfires once across failed retries until a connection succeeds. Intentional session teardown does not emit a public error.this. A weak callback map preserves listener identity for removal, duplicate registrations and self-removal fromonce.connectedandenddispatch outside the transport promise chain, so a throwing application listener retains EventEmitter exception behavior instead of entering connection recovery.The README documents the four-method interface, which is not a complete Node.js EventEmitter implementation. It also explains that
getClient()returnsSimpleClientwithout lifecycle listeners, and that command errors can wrap connection errors incause.Local Execution
Current source:
4f0b105e9420010ebcc90cf246a231da10b2a53b; tree:7d5b1e2b4812894d8e3a45fd4e0df154b77c668f.GitHub reported a merge conflict, so this update normally merges upstream
af99cd9f7without rewriting the published history. The two conflict resolutions retain upstream operation constants and readiness groups alongside the reviewed lifecycle interface.Windows, Node 24:
prekrun encountered Windows shell/symlink limitations, so the same unmodified hooks were run on Linux below.Separate Ubuntu validation of this exact source:
prekhooks passed on Node 24. Commit/tree assertions and clean-tree checks passed after hooks and tests.This run covers the SDK and hooks. It does not rerun the real-server TCP/TLS/BDD suites. The earlier October 23 real-server validation and green upstream CI apply to
672e5ff1, not this new merge. Fresh upstream CI must validate the updated head.AI Usage
Claude Code wrote the original feature, tests and documentation. OpenAI Codex adapted the feature to #4561, implemented review corrections, resolved the two textual merge conflicts, prepared the validation harness and this description, and ran the recorded checks.
The user-invoked
team-review-slimreview examined the feature using four roles. Its applicable findings led to regression tests and corrections for listener context and exception dispatch. The report's original changes-requested verdict is retained; no independent approval of the subsequent corrections is claimed.The contributor supplied the rationale above, personally reviewed the October 22 patch, and subsequently confirmed that they reviewed and understood the October 23 corrections and can explain them before this update was published.