Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Node.js boolean map keys may be communicated incorrectly

Aperta
#2,981 3 commenti 1 reazione 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 3 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
48/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Tranquilla
Stack tecnologico
node.js, typescript
Ambito
api, backend

Direzione di ricerca

Inizia riproducendo il problema con il proto e la richiesta Node.js forniti, oppure esegui l’immagine Docker fornita e ./ls_run.sh. Traccia il modo in cui Node.js serializza le chiavi booleane delle mappe negli oggetti JavaScript e confronta i casi con chiave false con la risposta Python. Il lavoro è completo quando le chiavi false rimangono false nel round trip da Node.js a Python, con un test di regressione se viene individuata una struttura di test esistente.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

package: @grpc/proto-loader
Problem description

Hi all, we found an interesting bug. Given a map field which contained a key of type bool, when using a Node.js client to send the map field to a Python server, boolean keys in map fields are incorrectly deserialized in the response. Specifically, False keys are converted to True in the returned message.

Reproduction steps

The code snippet to help reproduce the issues is provided in Google drive.
You can reproduce the issue in either of the following two ways:

Option 1. Here is a simplified version of the code to reproduce the issue:
Proto file.

syntax = "proto3";

package map_hotpot;

option java_multiple_files = true;
option java_package = "org.grpctest.java.common.define";
option java_outer_classname = "MapProto";

message MapPot {
 map<bool, double> bool_double_value = 1;
 map<bool, int64> bool_int_value = 2;
 map<bool, bool> bool_bool_value = 3;
 map<bool, string> bool_string_value = 4;
}

service HotpotService {
 // UNARY
 rpc UnaryPot(MapPot) returns (MapPot);
}

Nodejs client request message:

const request = {
    bool_double_value: { true: 3.14 },
    bool_int_value: { false: 42 },
    bool_bool_value: { true: true },
    bool_string_value: { **false**: "hello" }
};

The response message as received by Python client

python server Received request: bool_double_value {
  key: true
  value: 3.14
}
bool_int_value {
  key: true
  value: 42
}
bool_bool_value {
  key: true
  value: true
}
bool_string_value {
  key: true
  value: "hello"
}

We can see that the second and fourth key are switched from "false" to "true", which is expected.

Option 2. For your convenience, we’ve provided the Docker image.
Load the Docker image: You can access it via this command ``docker pull lishuoiscas/grpc_app:0723
Prepare the code:
Create a folder named grpc-auto-test
Place the relevant code inside this folder
Run the Docker container:
Replace {your_path} with the absolute path to your local grpc-auto-test folder:
docker run -it --rm -v {your_path}/grpc-auto-test:/grpc-auto-test <image:tag>
Inside the container, reproduce the issue by running:

./ls_run.sh

Environment
  • MacOs 15.3 and Windows 11
  • Node version 22.17.1
    -Python 3.13
Additional context

Plausible reason: We confirmed the problem originated from Node.js server by analysing the response sent from Node.js server, as captured by tcpdump. This issue stemmed from the way Node.js convert map values to Javascript objects, where map keys must be a string. We have not found sufficient gRPC-node documentation to determine the exact cause behind this issue. However, it is very likely that the issue was caused by how the string form of map keys, as stored in Javascript objects, was converted to boolean type during serialization. In Javascript, the string “false”, when converted to a boolean value, will be boolean true (refer to the debuggping_process_1.png). If our assumption is true, then one solution to patch this bug would be to introduce a simple condition during string to boolean conversion as shown in the debuggping_process_2.png.
Please note that the suggested change was not based on gRPC-node code, it simply suggested a general idea to fix this issue.

Can you help fix it or double check it? Thank you.

Lingua principale
TypeScript
Stelle
4.8k
Fork
721
Merge medio
2g 22h
PR unite (30g)
17

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di grpc/grpc-node

Tutte le issue di grpc/grpc-node

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.