Function lookup with an expected output content type modifies the shared cached function wrapper

Offen
#1,534 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Anfängerfreundlichkeit
45/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
java
Bereich
backend

Rechercherichtung

Start in SimpleFunctionRegistry.doLookup(..) and the wrappedFunctionDefinitions cache it reads from, listing every mutable per-lookup field on the wrapper (expectedOutputContentType, skipInputConversion, skipOutputConversion, the input header enhancer, propagateInputHeaders). Then trace where the invocation applies those settings to see whether they can be passed per call instead of stored. The fix is done when a new test looks up one function concurrently with different expected content types and each result keeps its own, with existing registry tests still green.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

5.0.x backport bug

SimpleFunctionRegistry.doLookup(..) assigns the requested output mime types to the wrapper it returns (function.expectedOutputContentType = expectedOutputMimeTypes). That wrapper is usually the instance cached in wrappedFunctionDefinitions and shared by all callers, because functions are singletons by default.

This has two consequences:

  • concurrent lookups of the same function definition with different expected content types (for example HTTP requests with different Accept headers) overwrite each other's value on one shared, non-volatile field, so a request may be converted to the content type that another request asked for
  • the field is only assigned when mime types are given and is never reset, so a later lookup without mime types still uses the content type left by an earlier caller

The wrapper holds other per-lookup state with the same problem: skipInputConversion, skipOutputConversion, the input header enhancer and propagateInputHeaders.

Proposed change: do not modify the cached wrapper. Return a lightweight per-lookup view or copy when a lookup needs different settings (or pass the expected content type with the invocation), and add a test that looks up the same function concurrently with different content types and verifies that each result uses its own.

Vorherrschende Sprache
Java
Sterne
1.1k
Forks
655
Ø Merge
4 Std. 54 Min.
Gemergte PRs (30 T.)
10

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus spring-cloud/spring-cloud-function

Alle Issues in spring-cloud/spring-cloud-function

Ähnliche Issues

Weitere Issues zu Java

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.