-
Notifications
You must be signed in to change notification settings - Fork 86
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
fix: protoCache map key support Buffer type #1106
Conversation
src/fallback.ts
Outdated
@@ -81,7 +81,7 @@ export class GrpcClient { | |||
authClient?: AuthClient; | |||
fallback: boolean | 'rest' | 'proto'; | |||
grpcVersion: string; | |||
private static protoCache = new Map<string, protobuf.Root>(); | |||
private static protoCache = new Map<string | Buffer, protobuf.Root>(); |
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.
Would it make sense to be more confident in the types of the internal data structure and ensure we always have a string key?
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.
Alternative way is to turn the hash
value from Buffer to string. At line
const hash = objectHash(json).toString()
;
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.
Just confirm that you want a key lookup for a string and its Buffer representation to refer to the same cached object.
🤖 I have created a release \*beep\* \*boop\* --- ### [2.25.3](https://www.github.com/googleapis/gax-nodejs/compare/v2.25.2...v2.25.3) (2021-09-14) ### Bug Fixes * protoCache map key support Buffer type ([#1106](https://www.github.com/googleapis/gax-nodejs/issues/1106)) ([a7ce8ab](https://www.github.com/googleapis/gax-nodejs/commit/a7ce8abc11be39722f6060f74b4d54ce6461dd40)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
Tests fails at
The current
GrpcClient.protoCache
map key isString
type. hash returnString | Buffer
.Fix Solution:
Option 1: Allow maps key has two types, String | Buffer
Option 2: Secure the key as String type, but turn the
hash
value fromobjectHash
Buffer to String by usingtoString()
,