Title: stream: fix TransformStream race on cancel with pending write by marcopiraccini · Pull Request #62040 · nodejs/node · GitHub
Open Graph Title: stream: fix TransformStream race on cancel with pending write by marcopiraccini · Pull Request #62040 · nodejs/node
X Title: stream: fix TransformStream race on cancel with pending write by marcopiraccini · Pull Request #62040 · nodejs/node
Description: Fixes: #62036 Fix a race condition in TransformStream where a late writer.write() racing with reader.cancel() could throw an internal TypeError: controller[kState].transformAlgorithm is not a function The race occurs when cancel/abort/close clears the controller's algorithms via transformStreamDefaultControllerClearAlgorithms while a pending write reaches transformStreamDefaultControllerPerformTransform Added a guard in transformStreamDefaultControllerPerformTransform to check if transformAlgorithm is still callable before invoking it Race sequence reader.read() releases backpressure reader.cancel() triggers transformStreamDefaultSourceCancelAlgorithm, which calls transformStreamDefaultControllerClearAlgorithms — sets transformAlgorithm = undefined writer.write() enters transformStreamDefaultSinkWriteAlgorithm and calls transformStreamDefaultControllerPerformTransform performTransform tries to invoke transformAlgorithm() which is now undefined → TypeError Fix Guard transformStreamDefaultControllerPerformTransform so that if transformAlgorithm has been cleared (stream is shutting down), the write returns silently rather than throwing an internal error. The writable side's existing error handling surfaces the appropriate stream-level error to the caller. Spec note The WHATWG streams reference implementation has the same unguarded call in TransformStreamDefaultControllerPerformTransform. The race is latent in the spec but rarely surfaces in browsers due to WebIDL callback wrapping adding an extra promise tick that changes the interleaving order (see whatwg/streams#1296). Node.js hits it consistently because it lacks that extra indirection layer. Test plan New test test/parallel/test-whatwg-transformstream-cancel-write-race.js reproduces the race.
Open Graph Description: Fixes: #62036 Fix a race condition in TransformStream where a late writer.write() racing with reader.cancel() could throw an internal TypeError: controller[kState].transformAlgorithm is not a func...
X Description: Fixes: #62036 Fix a race condition in TransformStream where a late writer.write() racing with reader.cancel() could throw an internal TypeError: controller[kState].transformAlgorithm is not a func...
Opengraph URL: https://github.com/nodejs/node/pull/62040
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:a63b641c-f81e-9678-f3b1-8b54e0490147 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | DA06:1BB557:1171C2:176C82:6A4C2163 |
| html-safe-nonce | 9865f45ebfa78708532536e7eb0baf7911de25bb0ee638f37ba7a96eff36258c |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEQTA2OjFCQjU1NzoxMTcxQzI6MTc2QzgyOjZBNEMyMTYzIiwidmlzaXRvcl9pZCI6IjkxMTczMjA0MjI2OTc0NzY0NTEiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 52f4b9968c0633fbccaac16dade856f7cbd3d00c99f8b2ca8e9d7491741db51c |
| hovercard-subject-tag | pull_request:3338788369 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/nodejs/node/pull/62040/files |
| twitter:image | https://avatars.githubusercontent.com/u/668050?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/668050?s=400&v=4 |
| og:image:alt | Fixes: #62036 Fix a race condition in TransformStream where a late writer.write() racing with reader.cancel() could throw an internal TypeError: controller[kState].transformAlgorithm is not a func... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 1b6b16d04026f131a36d57e3b01d0f4d26a51800edf48bf5ed0256e0ac905511 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/nodejs/node git https://github.com/nodejs/node.git |
| octolytics-dimension-user_id | 9950313 |
| octolytics-dimension-user_login | nodejs |
| octolytics-dimension-repository_id | 27193779 |
| octolytics-dimension-repository_nwo | nodejs/node |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 27193779 |
| octolytics-dimension-repository_network_root_nwo | nodejs/node |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | f95fb36c72adc940ff991c03531114b2245658d0 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width