Skip to content

ThreadContext.REQUEST #134

Open
Open
@gavinking

Description

@gavinking

Currently it's possible to control propagation of contexts via passing of Stringly-typed identifiers. There are some standard identifiers defined by ThreadContext. For example, ThreadContext.TRANSACTION is useful to control exactly when transaction contexts are propagated to long-running asynchronous jobs.

However, there is no standard identifier for the very important request context. As I understand it, the current behavior is that if a JAX-RS client calls a ManagedExecutor to start a job, then:

  1. the JAX-RS request context (the thread-bound request and response objects) is propagated to the asynchronous thread, but
  2. the CDI request scope is not, unless by some accident of the underlying implementation, CDI happens to be collaborating with JAX-RS in a way that is currently undefined by the spec.

(If my understanding here is wrong, please could someone correct me.)

Assuming that my understanding is correct, well, it's broken.

  • CDI request scope propagation should be consistent with how JAX-RS propagates its context, and
  • by default, the JAX-RS request context should not be propagated by a ManagedExecutor.

And we don't even give the user a very good way to control request context propagation, since there is no standard way to identify the JAX-RS contexts.

I therefore propose that:

  • we add ThreadContext.REQUEST, and specify
  • that it is not propagated by default when the user explicitly calls ManagedExecutor, and
  • that CDI propagates its request scope whenever iff the REQUEST context is propagated.

We don't need to limit ThreadContext.REQUEST to always mean the JAX-RS request, just as the CDI request scope doesn't always mean a servlet request.

Note that the required behavior for ThreadContext.REQUEST is extremely similar to ThreadContext.TRANSACTION. It should be propagated along a reactive stream, but not (by default) to a ManagedExecutor job.

Hope I'm not misunderstanding something fundamental here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions