Skip to content

NaN float values fail in gRPC tests and in console.log #3990

@hanlaur

Description

@hanlaur

Brief summary

I am trying to load test gRPC service where some inputs are arrays of floats and the arrays may contain NaNvalues.

The gRPC.Client().invoke serialization fails due toNaN value being incorrectly treated as null. Same applies to Infinity values.

Error message from the gRPC invoke:

ERRO[0000] GoError: unable to serialise request object to protocol buffer: proto: (line 1:39): invalid value for float type: null

Similar (possibly related) behavior is visible also with console.log when logging objects/arrays where NaN values get logged as null. Logging individual NaN values works fine.

k6 version

k6 v0.54.0 (go1.23.1, darwin/amd64)

OS

MacOS 14.7

Docker version and image (if applicable)

No response

Steps to reproduce the problem

Below is a simplified test demonstrating the behavior for both gRPC.Client().invoke and console.log:

test.js:

import { check } from 'k6';
import grpc from 'k6/net/grpc';

const client = new grpc.Client();
client.load(['.'], 'dummy.proto');

export default () => {
  client.connect('localhost:8081', {
    plaintext: true,
  });

  const payload = {
    single_float: NaN,
    array_float: [1.0, NaN, Infinity, -Infinity, 5.0]
  };


  // Will be logged incorrectly: {"single_float":null,"array_float":[1,null,null,null,3]}
  console.log(payload)

  // Will be logged correctly: NaN
  console.log("single float", payload.single_float)

  // Will be logged correctly
  for (let i = 0; i < payload.array_float.length; i++) {
    console.log("array", i, payload.array_float[i])
  }

  // Will fail: GoError: unable to serialise request object to protocol buffer: proto: (line 1:39): invalid value for float type: null
  const response = client.invoke('dummy.DummyService/Do', payload);

  console.log(response)

  check(response, {
    'status is OK': (r) => r && r.status === grpc.StatusOK,
    });

  client.close();
};

dummy.proto:

syntax = "proto3";

package dummy;

service DummyService
{
  rpc Do(DummyRequest) returns (DummyResponse) {}
}


message DummyRequest
{
  float single_float = 1;
  repeated float array_float = 2;
}

message DummyResponse
{
  float single_float = 1;
}

resulting log messages when executing test

INFO[0000] {"single_float":null,"array_float":[1,null,null,null,5]}  source=console
INFO[0000] single float NaN                              source=console
INFO[0000] array 0 1                                     source=console
INFO[0000] array 1 NaN                                   source=console
INFO[0000] array 2 Infinity                              source=console
INFO[0000] array 3 -Infinity                             source=console
INFO[0000] array 4 5                                     source=console
ERRO[0000] GoError: unable to serialise request object to protocol buffer: proto: (line 1:39): invalid value for float type: null

Expected behaviour

NaN value in the payload should be properly encoded as NaN float in the gRPC call and should not cause error.

Actual behaviour

NaN value in the payload causes error:
ERRO[0000] GoError: unable to serialise request object to protocol buffer: proto: (line 1:39): invalid value for float type: null

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions