Same-date blocking states: an unblock inserted before its block is silently dropped and billing stops permanently

Abierto
#2,328 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
48/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
java
Área
backend, payments

Línea de trabajo

Start with BlockingStateService.addBlockingState, then trace DefaultBlockingState.compareTo and BlockingCalculator.eventsToRemove to understand how same-date states affect billing events. Add regression coverage for both insertion orders, including the case where an unmatched unblock arrives first; done means both orderings produce the same intended billing outcome and future events are not silently removed.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

Two blocking states with the same effective date produce opposite outcomes depending only on which was created first, and one of those outcomes removes every future billing event for the subscription with nothing to restore it.

The two orderings, same two facts, same instant:

created first result
block, then unblock no blocking applied (correct: the pair matches, the zero-day duration is discarded)
unblock, then block blocked from that instant with a null end date, no re-enable, forever

The mechanism. BlockingStateService.addBlockingState is a two-branch state machine with no else:

if (currentBlockingState.isBlockBilling() && firstBlockingState == null) {
    perObjectTypeFirstBlockingState.put(currentBlockingState.getBlockedId(), currentBlockingState);
} else if (!currentBlockingState.isBlockBilling() && firstBlockingState != null) {
    addDisabledDuration(firstBlockingState, currentBlockingState.getEffectiveDate());
    perObjectTypeFirstBlockingState.put(currentBlockingState.getBlockedId(), null);
}

An unblock arriving with no open block matches neither branch and is discarded without a log. Ordering for same-date states comes from DefaultBlockingState.compareTo: effectiveDate, then createdDate, then totalOrdering, so insertion order decides which of the two rows above you get.

The surviving block is then closed by build() with a null end, and addDisabledDuration's end == null short-circuits the one-day minimum, so the unbounded duration is always added. BlockingCalculator.eventsToRemove removes every billing event on or after the start when duration.getEnd() == null, and createNewEvents documents the rest itself: "no second event in the pair means they are still disabled (no re-enable)".

Reachability. DefaultSubscriptionApi.addBlockingState validates the service name and reserved state names only; its own comment says "This is in no way an exhaustive arg validation". Nothing requires an unblock to have a matching open block, so a caller correcting a mistake, or a plugin writing both states in one batch, can produce the second ordering through the public API.

How this was checked, stated plainly. I transcribed the pairing logic into a small script and ran both orderings against the transcription, checked line by line against the Java at 3868a5b. I did not run Kill Bill itself for this one, and no invoice was generated, so this is a code-reading finding with a transcription-level reproduction, not an end-to-end one. It is the same event-collision family as #2320 and #2321.

Suggested direction. At minimum, an else branch that logs an unmatched unblock, so a permanent silent billing stop becomes something an operator can find. The stronger fix is treating an unmatched unblock as closing at its own effective date regardless of insertion order, which makes the outcome order-independent. Happy to write the regression test against the released tag the way #2320 and #2321 were done, if that is useful.

Lenguaje dominante
Java
Estrellas
5.9k
Forks
980
Merge medio
3 d 10 h
PR fusionados (30 d)
5

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de killbill/killbill

Todos los issues de killbill/killbill

Issues similares

Más issues de Java

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.