Don't hold a DB connection during token validation of incoming negotiation and transfer messages

Aperta
#6,183 3 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
54/100
Tipo di issue
Refactoring
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
java
Ambito
backend, databases

Direzione di ricerca

Start by reading ContractNegotiationProtocolServiceImpl and TransferProcessProtocolServiceImpl, then compare the catalog-request change in #6180. Trace each notify* method’s transaction, verification, lease, and save steps; done means verification runs outside the write transaction while the leased action still re-reads and checks state, with the JTI retry behavior and policy staleness considerations addressed.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

feature_request triage

Feature Request

Validate the counter-party's token of incoming DSP negotiation and transfer messages outside the transaction that
leases and updates the entity, as #6180 did for catalog requests.

Which Areas Would Be Affected?

control-plane-aggregate-services: ContractNegotiationProtocolServiceImpl, TransferProcessProtocolServiceImpl.

Why Is the Feature Desired?

Every notify* method runs inside one transactionContext.execute(...):

  1. read the negotiation or transfer (or the offer);
  2. protocolTokenValidator.verify(...);
  3. lease, apply the message, save.

Token validation makes remote calls: DID resolution, the DCP presentation request to the counter-party's credential
service, and STS signing. It also runs SQL before them (the entity read, the JTI replay check, participant config). So
the transaction's connection stays checked out, idle in transaction, for the whole remote round trip.

In a load test (40 negotiation+transfer flows/s), Postgres showed 27–37 connections idle in transaction against 1–9
active. A thread dump showed 21 request threads in DefaultCredentialServiceClient.sendRequest, under
LocalTransactionContext.execute (e.g. TransferProcessProtocolServiceImpl.notifyTerminated). The pool must
therefore be sized for the slowest credential service, not for the database work.

Solution Proposal

  • Read what verification needs outside the write transaction, i.e. the entity, or the offer for notifyRequested, to
    get the policy whose scopes are requested. Each store call runs its own short transaction.
  • Call verify outside any transaction.
  • Then transactionContext.execute { findByIdAndLease + action + save }. The leased action already re-reads the
    entity and checks its state.

Points to discuss:

  • JTI replay entry: today a failure after validation (e.g. 409 on a held lease) rolls back the JTI insert, so a
    retry with the same token passes. With validation outside the transaction, the JTI entry is committed, and a retry
    with the same token gets 401. EDC builds a new token per dispatch, but the HTTP client's automatic retry re-sends
    the same request (see the related signaling issue).
  • Policy staleness: the policy used for the scopes is read before the lease. It changes only through a later offer
    message, which the state checks of the leased action reject anyway.
  • Participant config reads during validation no longer share the request's transaction cache (see the config
    cache issue).
Lingua principale
Java
Stelle
429
Fork
302
Merge medio
10h 46m
PR unite (30g)
75

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di eclipse-edc/Connector

Tutte le issue di eclipse-edc/Connector

Issue simili

Altre issue su Java

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.