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.

Automatic propagation of RequestContext

See original GitHub issue

One of the most complaints from the users is that they are struggling to propagate a RequestContext. Check out this snippet:

@Override
public HttpResponse serve(ServiceRequestContext ctx, HttpRequest req) throws Exception {
    backend1.execute(req).aggregate().handle((aggregatedRes, cause) -> {
        // ctx is not in the thread-local. You should use ctx.makeContextAware() or contextAwareExecutor
        backend2.execute(req)...
    });
    ...             
    return res;
}

If we return a RequestContextAwareCompletebleFuture from aggregate() call, most of the situations are solved because RequestContextAwareCompletebleFuture keeps spwaning the future itself when adding callbacks.

Of course, we cannot propagate the ReqeustContext all of the cases. For example, if a user creates a new CompletableFuture instance and completes it with a value, the RequestContextAwareCompletebleFuture will stop spawning. So he/she has to understand how the propagation works to use Armeria properly.

However, I think Automatic propagation will still reduce the burden of users who are not familiar with the asynchronous server and can lower the entry point.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:15 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
anuraagacommented, Dec 27, 2019

However, I think Automatic propagation will still reduce the burden of users who are not familiar with the asynchronous server and can lower the entry point.

I think you know my opinion 😉

If relying on context and writing an asynchronous server, knowing how context works is a requirement - I find bandaids to be worse since the context bug will inevitably appear, but later in the lifecycle of the codebase and has an even higher chance of affecting production vs development servers. Being confused in the beginning is better than later IMO.

Also, IMO writing asynchronous code effectively basically requires a framework on top of Armeria for a reasonable sized app. I personally know Dagger makes it trivial to solve the context problem completely where it would be harder for a user to make a mistake than do the right thing. I have heard of rxjava users forgetting to subscribe correctly - perhaps enforcing use of something like ArmeriaFlux that automatically subscribes would be harder to forget. I was a little interested in seeing what approaches could help with RxJava but currently have no plans of using it so not sure if I could come up with anything but it seems like a better layer to deal with asynchronous issues than our custom CompletableFuture implementation.

Also just for reference, golang and gRPC both have context and take the approach of no automation at all (note, the Armeria context is a combination of gRPC concepts of Call and Context, only Call is automatic in gRPC). Creating and propagating context is all up to the user. This creates some tedium, and I do think automatically creating context like Armeria does is better, but I do like how it forces users to understand context before using it.

These are my opinions and some reference point, I wouldn’t say no if everyone still felt automatic propagation makes sense 😃

0reactions
minwooxcommented, Jan 9, 2020

@minwoox Thanks for the ServiceRequestContext.contextAwareExecutor reference.

It’s not me. Thanks to @anuraaga. 😆

Read more comments on GitHub >

github_iconTop Results From Across the Web

Context Management
RequestContext. BoundRequestContext. A request context bound to a manually propagated map, useful for testing or non-Servlet environments.
Read more >
RequestContext Class (Orleans.Runtime) - Microsoft Learn
Information stored in RequestContext is propagated from Orleans clients to Orleans grains automatically by the Orleans runtime.
Read more >
Context Propagation over HTTP in Go - Jaana Dogan - Medium
There is no automatic way to put the context into an HTTP request or ... the request context, will be propagated as the...
Read more >
The Request Context — Flask Documentation (2.2.x)
Flask automatically pushes a request context when handling a request. ... are not converted to a 500 response and instead are propagated to...
Read more >
Context Propagation | Signadot
OpenTelemetry simply provides a convenient set of libraries that can take care of propagating the request context for us across the services automatically....
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