fix: preserve callback state when wrapping requests - #252
Open
alexandroit wants to merge 1 commit into
Open
alexandroit wants to merge 1 commit into
alexandroit wants to merge 1 commit into
Conversation
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.
Summary
HttpClient.requestwraps caller-provided callbacks withonce. The publishedonce@1.4.0wrapper copies enumerable callback properties after initializingits own state, so a callback that already owns
calledorvaluecan suppressits first invocation or expose a value before it runs.
This change:
require('once')imports unchanged by using an npmalias under the historical
oncedependency key;@stackline/once@1.0.0, an ISC compatibilitycontinuation with zero runtime dependencies; and
HttpClient.requestpath proving adecorated callback starts with clean wrapper state, runs exactly once, and
retains the wrapper's public
calledstate.No Restify source import or public API changes.
Package: https://www.npmjs.com/package/@stackline/once/v/1.0.0
Source/release: https://github.com/alexandroit/stackline-once/releases/tag/stackline-v1.0.0
Verification
oncekeyresolves to
@stackline/once@1.0.0with zero runtime dependencies;make lint;make codestyle;24.19.0, and 26.8.1;
reserved once stateregression: 1 passing on each of Node 22, 24,and 26;
preservation, package identity, and the zero-dependency tree.
For comparison, the focused regression fails against the current
once@1.4.0dependency becausewrappedCallback.calledis alreadytrue, andpasses with this alias.
I also ran the complete local
make coveragesuite. It reached 232 passing and6 host-environment failures, all outside the changed code: fixed port 8080 was
already occupied in the socket-close test, and five tests expecting a delayed
ConnectTimeoutErrorreceived an immediate generic network error for10.255.255.1on this host. The deterministic runs above exclude the fixed-portand connect-timeout cases; no other test was excluded or failed.
Disclosure
I maintain
@stackline/once, so this pull request proposes a package I publish.The package is a compatibility-focused continuation of the ISC-licensed once
line and is not affiliated with or endorsed by the original once maintainers.