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

MicrometerObservationListener stops Observation twice #3972

Closed
chemicL opened this issue Jan 22, 2025 · 3 comments
Closed

MicrometerObservationListener stops Observation twice #3972

chemicL opened this issue Jan 22, 2025 · 3 comments
Assignees
Labels
Milestone

Comments

@chemicL
Copy link
Member

chemicL commented Jan 22, 2025

Since the introduction of ObservationValidator in Micrometer, reactor-core-micrometer can produce errors on cancelled Monos that already delivered a value.

Originally reported in micrometer-metrics/micrometer#5802 by @mathiaskinzler.

Expected Behavior

No error logs should happen.

Actual Behavior

io.micrometer.observation.tck.InvalidObservationException: Invalid stop: Observation 'reactor.observation' has already been stopped

Steps to Reproduce

	@Test
	void monoCancelAfterNext() {
		TestObservationRegistry observationRegistry = TestObservationRegistry.create();
		Mono<Integer> mono = Mono.just(1).tap(Micrometer.observation(observationRegistry));
		StepVerifier.create(Flux.from(mono).take(1).single())
		            .expectNext(1)
		            .expectComplete()
		            .verify();
	}

Possible Solution

Analyze and fix the state machine in MicrometerObservationListener.

Your Environment

  • Reactor version(s) used: 3.7.3-SNAPSHOT
  • Other relevant libraries versions (eg. netty, ...): io.micrometer:micrometer-bom 1.14.3
@chemicL chemicL self-assigned this Jan 22, 2025
chemicL added a commit that referenced this issue Jan 27, 2025
This change prevents multiple `Observation.stop` calls with proper
guardrails in `MicrometerObservationListener`. Since cancellation can
happen out-of-band on a different `Thread`, a `volatile` state has been
introduced to prevent duplicate `Observation` terminations.

Resolves #3972

Signed-off-by: Dariusz Jędrzejczyk <[email protected]>
@chemicL chemicL added this to the 3.6.14 milestone Jan 27, 2025
@chemicL
Copy link
Member Author

chemicL commented Jan 27, 2025

@mathiaskinzler the issue should be resolved. If you get a chance to experiment with the 3.7.3-SNAPSHOT, any feedback is appreciated.

@mathiaskinzler
Copy link

@chemicL We have now updated to spring boot starter 3.4.3 and things work like a charm. Thanks for your support.

@chemicL
Copy link
Member Author

chemicL commented Feb 21, 2025

@mathiaskinzler glad to hear it! Thanks a lot for the update :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants