-
Notifications
You must be signed in to change notification settings - Fork 79
Add polyfill for AbortSignal.any() for Node.js <= 20.3.0 #1322
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -19,6 +19,32 @@ const DistroUtils = require('./distro.js'); | |||||||||||||||||||||||||||
| const Entity = require('./entity.js'); | ||||||||||||||||||||||||||||
| const debug = require('debug')('rclnodejs:client'); | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| // Polyfill for AbortSignal.any() for Node.js <= 18.20 | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
| // Polyfill for AbortSignal.any() for Node.js <= 18.20 | |
| // Polyfill for AbortSignal.any() for Node.js < 20.3.0 |
Outdated
Copilot
AI
Nov 11, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The polyfill doesn't handle edge cases such as an empty signals array or null/undefined signals. Consider adding validation: if the array is empty, return AbortSignal.abort() (or create a never-aborting signal), and filter out any null/undefined values from the signals array to prevent runtime errors.
| const controller = new AbortController(); | |
| for (const signal of signals) { | |
| // Filter out null/undefined signals | |
| const validSignals = Array.isArray(signals) | |
| ? signals.filter(s => s != null) | |
| : []; | |
| if (validSignals.length === 0) { | |
| throw new TypeError('AbortSignal.any: signals array is empty'); | |
| } | |
| const controller = new AbortController(); | |
| for (const signal of validSignals) { |
Outdated
Copilot
AI
Nov 11, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The polyfill has a potential memory leak. When event listeners are added to input signals, they should be removed after the controller aborts to prevent memory leaks. Consider storing references to the listeners and removing them after controller.abort() is called, or use an AbortController that can be used to clean them up.
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -260,6 +260,12 @@ describe('Client async functionality', function () { | |||||
| }); | ||||||
|
|
||||||
| it('should handle zero and negative timeouts', async function () { | ||||||
| // Skip this test on Node.js < 18.20 where AbortSignal.timeout(0) throws RangeError | ||||||
|
||||||
| // Skip this test on Node.js < 18.20 where AbortSignal.timeout(0) throws RangeError | |
| // Skip this test on Node.js < 18.20.0: AbortSignal.timeout() was added in 17.3.0, but support for zero timeout values was only fixed in 18.20.0 (prior versions throw RangeError for AbortSignal.timeout(0)) |
Copilot
AI
Nov 12, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The version parsing only extracts major and minor versions but doesn't handle the patch version. If process.versions.node is '18.20.1', the comparison major === 18 && minor < 20 will work, but the destructuring should explicitly acknowledge that patch (and potentially pre-release) versions exist. Consider using const [major, minor] = process.versions.node.split('.').slice(0, 2).map(Number); to make it explicit that only the first two components are used.
| const [major, minor] = process.versions.node.split('.').map(Number); | |
| const [major, minor] = process.versions.node.split('.').slice(0, 2).map(Number); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Node.js 16.X reached end-of-life in September 2023 and is no longer receiving security updates. While testing on older versions may be valuable for backward compatibility, consider also testing on a supported version (18.X or 20.X) to ensure the polyfill works correctly on both old and new versions. The x64 workflow tests on 24.X and 25.X, creating a large version gap in test coverage.