Skip to content

[Bug] Self-invocation bypasses @Async/@Transactional/@PreAuthorize on registerSamplesFromMetadata #1702

Open

Description

@KochTobi-Agent

What actually happened?

registerSamples calls registerSamplesFromMetadata as a self-invocation, so the Spring AOP annotations on the callee never take effect:

// SampleRegistrationServiceV2.java:103-105
return registerSamplesFromMetadata(metadata, projectId, experimentReference);
// SampleRegistrationServiceV2.java:108-114
@PreAuthorize("...")
@Async
@Transactional
public CompletableFuture<Void> registerSamplesFromMetadata(...)

Because the call goes through this rather than through the Spring proxy, @Async, @Transactional and @PreAuthorize on registerSamplesFromMetadata are bypassed on this path. @Async returns a plain CompletableFuture.completedFuture(null) rather than being scheduled, and the method body runs in the caller's thread and transaction.

Current practical impact is limited and this is filed mainly as code health, not as a live defect: the outer registerSamples (:73-75) already carries @Async, @Transactional and an equivalent @PreAuthorize, so the registration still runs asynchronously, transactionally and with the same permission check. Nothing is broken today.

The risk is that the annotations on the callee are actively misleading:

  • A reader reasonably assumes registerSamplesFromMetadata establishes its own transaction boundary. It does not — it inherits the caller's. That is exactly why the compensating deleteSamples call inside it cannot work (see [Bug] Sample registration compensation cannot work: doomed transaction, empty list, or never reached #1698): a REQUIRES_NEW boundary cannot be introduced from within a self-invoked method.
  • If a future caller (a new API endpoint, a test, another service) invokes registerSamplesFromMetadata through the proxy, behaviour changes silently: no transaction would enclose the workflow if called from a non-transactional context, and @Async would suddenly apply.
  • The Spock test calls the method directly on an instance (SampleRegistrationServiceV2Spec.groovy:57), so the annotations are never exercised by tests at all.

What did you expect to happen?

One of:

  1. Remove the redundant annotations from registerSamplesFromMetadata and make the single transaction boundary explicit and documented (it belongs on the entry point), or
  2. Keep a real boundary on the callee and call it through the proxy (selfProxy / @Lazy self, the pattern already used by SampleRepositoryImpl (:48-54) and DeletionService (:30, 42, 51)).

Option 2 is a prerequisite if compensation is to be implemented as a separate transaction anywhere in this flow. This is closely tied to #1698 and #1694, and should be decided together with them rather than fixed in isolation.

Steps to reproduce

  1. Set a breakpoint in registerSamplesFromMetadata and compare Thread.currentThread().getName() with the caller's — it is identical, showing no async dispatch for the inner call.
  2. Alternatively, log TransactionSynchronizationManager.isActualTransactionActive() inside both methods; the inner call adds no new boundary.

Affected application area

Sample Management

Browser(s) where the problem occurs

Not browser-specific / backend issue

Additional context

Code of Conduct

  • I agree to follow this project's Code of Conduct

Activity

  1. added
    bugSomething isn't working
    triageAn issue that is in discussion to be either scheduled for implepmentation or denied
    on Nov 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingtriageAn issue that is in discussion to be either scheduled for implepmentation or denied

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions