Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DataBufferUtils.write loses context #27517

Closed
ummels opened this issue Oct 4, 2021 · 1 comment
Closed

DataBufferUtils.write loses context #27517

ummels opened this issue Oct 4, 2021 · 1 comment
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: bug A general bug
Milestone

Comments

@ummels
Copy link

ummels commented Oct 4, 2021

The following code does not work as expected:

try (FileOutputStream out = new FileOutputStream("test2")) {
    DataBufferUtils.read(Path.of("test1"), new NettyDataBufferFactory(new PooledByteBufAllocator()), 1024, StandardOpenOption.READ)
        .transformDeferredContextual((f, ctx) -> {
            System.out.println("1: " + ctx.getOrDefault("key", "EMPTY"));
            return f;
        })
        .transform(f -> DataBufferUtils.write(f, out))
        .transformDeferredContextual((f, ctx) -> {
            System.out.println("2: " + ctx.getOrDefault("key", "EMPTY"));
            return f;
        })
        .contextWrite(Context.of("key", "TEST"))
        .subscribe();
}

Expected result:

2: TEST
1: TEST

Actual result:

2: TEST
1: EMPTY

Indeed, if you put Hooks.enableContextLossTracking(); Hooks.onOperatorDebug(); before that code, you see that the context is lost at DataBufferUtils.write where a new flux is created that does not pass the subsriber's context to the original flux.

Environment:

  • Spring Boot 2.5.5
  • Spring Framework 5.3.10
  • Project Reactor 3.4.10
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Oct 4, 2021
@poutsma poutsma self-assigned this Oct 4, 2021
@poutsma poutsma added in: core Issues in core modules (aop, beans, core, context, expression) type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Oct 5, 2021
@poutsma poutsma added this to the 5.3.11 milestone Oct 5, 2021
@poutsma poutsma closed this as completed in c99210c Oct 5, 2021
poutsma added a commit that referenced this issue Aug 16, 2022
This commit makes sure that the Reactor context is propagated in
DataBufferUtils::write(Path).

Closes gh-28933
See gh-27517
@lucianiz
Copy link

lucianiz commented Aug 3, 2023

This issue still happens in spring-framework 6.x . I recently updated to spring boot 3.1 and this causes problems.
@poutsma fyi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: bug A general bug
Projects
None yet
Development

No branches or pull requests

4 participants