Skip to content

Proxification of @Scheduled tasks using @Aspect in WebFlux seems broken after 3.2.0 #31755

Closed as not planned
@hypr2771

Description

@hypr2771

Description

Spring @Scheduled + @Aspect proxification issue after 3.2.0 upgrade seems broken.

Indeed, if you:

  • are proxifying @Scheduled method to add some logging and measurements
  • are using fixedDelay
  • are making your @Scheduled return a Publisher
  • are letting the proxy run the Publisher.subscribe
    tasks are no more scheduled after the single run upon restart in 3.2.0, while they still were in 3.1.5.

Environment

$ java -version
openjdk version "17.0.1" 2021-10-19
OpenJDK Runtime Environment (build 17.0.1+12-39)
OpenJDK 64-Bit Server VM (build 17.0.1+12-39, mixed mode, sharing)

No specific environment variables.

Reproduce

Minimal reproducible exemple here: https://github.com/hypr2771/spring_3_2_0_proxification_scheduling_issue.

Set your parent to 3.1.5

When in 3.1.5, @Scheduled proxification works perfectly:

mvn versions:update-parent -DparentVersion="[3.1.5]"
mvn clean package
mvn exec:java -Dexec.mainClass="org.example.Main"

Should look like:

2023-12-05T12:45:32.143+07:00  INFO 5615 --- [ple.Main.main()] org.example.Main                         : Starting Main using Java 17.0.1 with PID 5615 (/Users/vincentcastelluci/Workspace/Perso/Java/Tuto/spring_3_2_0_scheduling_issue/target/classes started by vincentcastelluci in /Users/vincentcastelluci/Workspace/Perso/Java/Tuto/spring_3_2_0_scheduling_issue)
2023-12-05T12:45:32.144+07:00  INFO 5615 --- [ple.Main.main()] org.example.Main                         : No active profile set, falling back to 1 default profile: "default"
2023-12-05T12:45:32.664+07:00  INFO 5615 --- [ple.Main.main()] o.s.b.web.embedded.netty.NettyWebServer  : Netty started on port 8080
Running scheduled Mono org.example.Task.test()
Ended scheduled Mono org.example.Task.test() with result 1701755132673
2023-12-05T12:45:32.697+07:00  INFO 5615 --- [ple.Main.main()] org.example.Main                         : Started Main in 0.632 seconds (process running for 1.555)
Running scheduled Mono org.example.Task.test()
Ended scheduled Mono org.example.Task.test() with result 1701755133681
Running scheduled Mono org.example.Task.test()
Ended scheduled Mono org.example.Task.test() with result 1701755134685

Set your parent to 3.2.0

When in 3.2.0, @Scheduled proxification seems broken:

mvn versions:update-parent -DparentVersion="[3.2.0]"
mvn clean package
mvn exec:java -Dexec.mainClass="org.example.Main"

Should look like:

2023-12-05T12:48:15.475+07:00  INFO 5724 --- [ple.Main.main()] org.example.Main                         : Starting Main using Java 17.0.1 with PID 5724 (/Users/vincentcastelluci/Workspace/Perso/Java/Tuto/spring_3_2_0_scheduling_issue/target/classes started by vincentcastelluci in /Users/vincentcastelluci/Workspace/Perso/Java/Tuto/spring_3_2_0_scheduling_issue)
2023-12-05T12:48:15.476+07:00  INFO 5724 --- [ple.Main.main()] org.example.Main                         : No active profile set, falling back to 1 default profile: "default"
Running scheduled Mono org.example.Task.test()
Ended scheduled Mono org.example.Task.test() with result 1701755295851
2023-12-05T12:48:16.000+07:00  INFO 5724 --- [ple.Main.main()] o.s.b.web.embedded.netty.NettyWebServer  : Netty started on port 8080
2023-12-05T12:48:16.009+07:00  INFO 5724 --- [ple.Main.main()] org.example.Main                         : Started Main in 0.646 seconds (process running for 2.494)

You can note the task is being run once on boot, rescheduled but never actually subscribed it seems.

Idea

No real clue but since it keeps working if we run the .subscribe on the @Scheduled process, my guess is that the underlying subscriber, related to changes made for async improvements, is disposed before it gets actually subscribed when returned by the proxified method.

It might also be due to the observability added to @Scheduled which might be doing instrumentation or proxification of those method.

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)status: invalidAn issue that we don't feel is valid

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions