Skip to content
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

Merged
merged 2 commits into from
Sep 14, 2021
Merged

fix: protoCache map key support Buffer type #1106

merged 2 commits into from
Sep 14, 2021

Conversation

summer-ji-eng
Copy link
Contributor

@summer-ji-eng summer-ji-eng commented Sep 14, 2021

Tests fails at

Argument of type 'string | Buffer' is not assignable to parameter of type 'string'.
  Type 'Buffer' is not assignable to type 'string'.

The current GrpcClient.protoCache map key is String type. hash return String | 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 from objectHash Buffer to String by using toString(),

@summer-ji-eng summer-ji-eng requested a review from a team as a code owner September 14, 2021 16:28
@google-cla google-cla bot added the cla: yes This human has signed the Contributor License Agreement. label Sep 14, 2021
@summer-ji-eng summer-ji-eng changed the title fix: map key support Buffer type fix: protoCache map key support Buffer type Sep 14, 2021
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>();
Copy link
Contributor

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?

Copy link
Contributor Author

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();

Copy link
Contributor

@chingor13 chingor13 left a 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.

@summer-ji-eng summer-ji-eng merged commit a7ce8ab into main Sep 14, 2021
@summer-ji-eng summer-ji-eng deleted the fix_bot branch September 14, 2021 17:07
gcf-merge-on-green bot pushed a commit that referenced this pull request Sep 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants