This repository was archived by the owner on Jan 18, 2026. It is now read-only.
fix: avoid unhandled exception when reusing a closed client#1640
Merged
sofisl merged 3 commits intogoogleapis:mainfrom Aug 30, 2024
Merged
fix: avoid unhandled exception when reusing a closed client#1640sofisl merged 3 commits intogoogleapis:mainfrom
sofisl merged 3 commits intogoogleapis:mainfrom
Conversation
7 tasks
Example:
* Execute streamingRecognize
* When done, close the client
* Execute streamingRecognize again, with data already in the stream
* Unhandled exception occurs.
TypeError [ERR_INVALID_ARG_TYPE]: The "chunk" argument must be of type string or an instance of Buffer or Uint8Array. Received an instance of Object
at _write (node:internal/streams/writable:474:13)
at Writable.write (node:internal/streams/writable:502:10)
at Duplexify._write (/project/node_modules/duplexify/index.js:212:22)
at doWrite (/project/node_modules/duplexify/node_modules/readable-stream/lib/_stream_writable.js:390:139)
at writeOrBuffer (/project/node_modules/duplexify/node_modules/readable-stream/lib/_stream_writable.js:381:5)
at Writable.write (/project/node_modules/duplexify/node_modules/readable-stream/lib/_stream_writable.js:302:11)
at Pumpify.<anonymous> (/project/node_modules/@google-cloud/speech/build/src/helpers.js:79:27)
at Object.onceWrapper (node:events:633:26)
at Pumpify.emit (node:events:518:28)
at obj.<computed> [as _write] (/project/node_modules/stubs/index.js:28:22)
at doWrite (/project/node_modules/duplexify/node_modules/readable-stream/lib/_stream_writable.js:390:139)
at writeOrBuffer (/project/node_modules/duplexify/node_modules/readable-stream/lib/_stream_writable.js:381:5)
at Writable.write (/project/node_modules/duplexify/node_modules/readable-stream/lib/_stream_writable.js:302:11)
at PassThrough.ondata (node:internal/streams/readable:1007:22)
at PassThrough.emit (node:events:518:28)
at addChunk (node:internal/streams/readable:559:12) {
code: 'ERR_INVALID_ARG_TYPE'
Reproduction: https://gist.github.com/orgads/13cbf44c91923da27d8772b5f10489c9
This happens because streamingRecognize writes streamingConfig on first
chunk. Usually the stream is open in object mode, so it works, but when
the client is terminated, PassThrough is used without object mode.
Change PassThrough to object mode, so it terminates gracefully.
This was reported in [1] and fixed in [2], but was then reverted in [3]
which re-generated the code. Fix properly in the generator now.
[1] googleapis/google-cloud-node#5464
[2] googleapis/google-cloud-node#5465
[3] googleapis/google-cloud-node#5565
8fe4485 to
b903729
Compare
Contributor
Author
|
@sofisl You approved the original fix. Please review this. |
sofisl
approved these changes
Aug 30, 2024
Contributor
Author
|
Thanks @sofisl. What's the next step to regenerate cloud-speech and refix googleapis/google-cloud-node#5464? |
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Example:
Reproduction: https://gist.github.com/orgads/13cbf44c91923da27d8772b5f10489c9
This happens because streamingRecognize writes streamingConfig on first chunk. Usually the stream is open in object mode, so it works, but when the client is terminated, PassThrough is used without object mode.
Change PassThrough to object mode, so it terminates gracefully.
This was reported in [1] and fixed in [2], but was then reverted in [3] which re-generated the code. Fix properly in the generator now.
[1] googleapis/google-cloud-node#5464
[2] googleapis/google-cloud-node#5465
[3] googleapis/google-cloud-node#5565