question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Blocking calls for gRPC and HTTP even though using Reactor

See original GitHub issue

Expected Behavior

Implementations of DaprClient API being non-blocking.

Actual Behavior

DaprClient API is reactive with Reactor. However, its implementations (gPRC and HTTP/1.x) at the moment are blocking, which defeats the purpose of using Reactive API. gRPC:

return Mono.fromCallable(wrap(context, () -> {
        ListenableFuture<DaprProtos.GetStateResponse> futureResponse = client.getState(envelope);
        return buildStateKeyValue(get(futureResponse), key, options, type);
      })).map(s -> new Response<>(context, s));
  private static <V> V get(ListenableFuture<V> future) {
    try {
      return future.get();
    } catch (Exception e) {
      DaprException.wrap(e);
    }

    return null;
  }

HTTP/1.1:

  public Mono<Response> invokeApi(
          String method,
          String[] pathSegments,
          Map<String, String> urlParameters,
          byte[] content,
          Map<String, String> headers,
          Context context) {
    return Mono.fromCallable(() -> doInvokeApi(method, pathSegments, urlParameters, content, headers, context));
  }

Note Mono.fromCallable only adapts the API to reactive. It still blocks a thread, be it the calling thread or the thread the Mono is subscribed on.

Steps to Reproduce the Problem

Release Note

RELEASE NOTE: FIXED implementations of DaprClient API were blocking for gRPC and HTTP.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
xiazuojiecommented, Jan 6, 2021

@xiazuojie Do you have a proposal to fix this? Since Java does not have async/await like .Net, I wonder how the Java community solves this.

Async is natively supported by gRPC java. HTTP/1.x is much more complicated. I’ll PR for gRPC.

0reactions
artursouzacommented, Jan 12, 2021

Thanks, @xiazuojie.

We only need the fix for HTTP now. GRPC is fixed.

On a side note, HTTP actually might become more relevant soon. As we are discussing if the invoke API should only be used over HTTP since gRPC to HTTP invocation cannot get the response to client easily translated due to core differences between the protocols.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Fully Reactive Request Processing with Project Reactor ...
Using Reactor bindings allows our code to more clearly express the cardinality between requests and responses, which is one-to-one (unary) in ...
Read more >
Performance Best Practices - gRPC
A user guide of both general and language-specific best practices to improve performance.
Read more >
Executing Blocking calls on a Reactor based Application
We used HttpsURLConnection since we know for sure that it is a blocking call. To do so we need a Scheduler. For the...
Read more >
Can I pass reactor Context into grpc clientInterceptor implicitly?
I came up with another solution that doesn't require a WebFilter or ... response = grpcStub .call(request); return Mono.just(response.
Read more >
Spring Cloud Gateway and gRPC
Even though reactor -netty has support for H2C clear-text protocol, Spring Cloud Gateway requires H2 with TLS to assure transport security. HTTP/ ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found