From 882588427b4c6230b4eb039aa789b402db935534 Mon Sep 17 00:00:00 2001 From: Peter Salin Date: Fri, 9 Sep 2022 09:56:11 +0300 Subject: [PATCH] Set grpc-timeout in milliseconds Setting it in nanoseconds overflowed the maximum length (8) of the header already at 100ms, causing PROTOCOL_ERROR responses. Using ms instead of nanoseconds is not bullet proof either, but covers the range of 1ms - ~27h. --- src/grpcbox_client_stream.erl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/grpcbox_client_stream.erl b/src/grpcbox_client_stream.erl index 5732cdd..5e62031 100644 --- a/src/grpcbox_client_stream.erl +++ b/src/grpcbox_client_stream.erl @@ -129,7 +129,8 @@ metadata_headers(Ctx) -> D when D =:= undefined ; D =:= infinity -> grpcbox_utils:encode_headers(maps:to_list(grpcbox_metadata:from_outgoing_ctx(Ctx))); {T, _} -> - Timeout = {<<"grpc-timeout">>, <<(integer_to_binary(T - erlang:monotonic_time()))/binary, "n">>}, + TimeMs = erlang:convert_time_unit(T - erlang:monotonic_time(), native, millisecond), + Timeout = {<<"grpc-timeout">>, <<(integer_to_binary(TimeMs))/binary, "m">>}, grpcbox_utils:encode_headers([Timeout | maps:to_list(grpcbox_metadata:from_outgoing_ctx(Ctx))]) end.