Skip to content

Resubmission of publications must not unregister in-progress publications in case of successful invocation #1051

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

Closed
buzhi-i opened this issue Feb 6, 2025 · 2 comments
Assignees
Labels
in: event publication registry Event publication registry type: bug Something isn't working
Milestone

Comments

@buzhi-i
Copy link

buzhi-i commented Feb 6, 2025

The processIncompletePublications method includes a retry mechanism for failed events and leverages the inProgress cache to improve efficiency. However, there is an issue:

1.In the finally block, the inProgress.unregister(it) method is redundantly called.
2.This leads to unnecessary cache invalidation because consuming events might be an asynchronous operation that has not been completed.
3.Both the markFailed and markCompleted methods already handle the inProgress.unregister operation, making the finally block unnecessary.

Suggested Fix:
Remove the finally block containing inProgress.unregister(it) to avoid redundant operations and improve code clarity.

Code Example of Current Implementation:

		publications.stream() //
				.filter(filter) //
				.forEach(it -> {

					try {

						inProgress.register(it);
						consumer.accept(it);

					} catch (Exception o_O) {

						if (LOGGER.isInfoEnabled()) {
							LOGGER.info("Error republishing event publication %s.".formatted(it), o_O);
						}

					} finally {
						inProgress.unregister(it);
					}
				});

Proposed Fix:

		publications.stream() //
				.filter(filter) //
				.forEach(it -> {

					try {

						inProgress.register(it);
						consumer.accept(it);

					} catch (Exception o_O) {

						if (LOGGER.isInfoEnabled()) {
							LOGGER.info("Error republishing event publication %s.".formatted(it), o_O);
						}

					}
				});
@odrotbohm odrotbohm self-assigned this Feb 7, 2025
@odrotbohm odrotbohm added in: event publication registry Event publication registry type: bug Something isn't working labels Feb 7, 2025
@odrotbohm
Copy link
Member

The explicit unregister was introduced for GH-891. Primarily to guard against target listeners not being advised to trigger markFailed(…)/markCompleted(…) imposing the theoretical risk of a publication staying in progress indefinitely. Revisiting that situation, it's clear that we might want to find alternative means to guard against that and rather reject the case rather than trying to adapt to it.

@odrotbohm odrotbohm added this to the 1.4 M2 milestone Feb 23, 2025
@odrotbohm odrotbohm changed the title Remove Redundant inProgress.unregister in DefaultEventPublicationRegistry.processIncompletePublications Resubmission of publications must not unregister in-progress publications in case of successful invocation Feb 23, 2025
odrotbohm added a commit that referenced this issue Feb 23, 2025
…rors.

Before this commit the code resubmitting incomplete event publications unregistered them independently of whether they succeeded or not. We now only do that for failed submissions as an error here indicates a failure to *submit* the publication. As the execution is likely performed asynchronously, a successful hand-off does not implicate the publication being completely processed.
@odrotbohm
Copy link
Member

I've moved the deregistration into the catch block, as an immediate exception indicates an error with the actual submission.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: event publication registry Event publication registry type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants