0

I am trying to guard groupBy from hanging indefinitely by adding the onBackPressureBuffer method. The following test works for multi = 1, i.e. 30000 groups, but hangs for every value of multi > 1.

    @Test
    void groupFluxHangsTest() {
        int numberOfTriggers = 30_000;
        int multi = 2;

        AtomicReference<UUID> idReference = new AtomicReference<>(UUID.randomUUID());
        Flux
                .range(0, numberOfTriggers)
                .map(i -> {
                    if (i % multi == 0)
                        idReference.set(UUID.randomUUID());
                    return idReference.get();
                })
                .groupBy(Function.identity())
                .onBackpressureBuffer(Integer.MAX_VALUE, System.out::println, BufferOverflowStrategy.ERROR)
                .flatMap(groupedFlux -> groupedFlux.reduce((a, b) -> b))
                .blockLast();
    }

I am aware of the description of groupBy saying it might hang if downstream is too slow, but onBackPressureBuffer does request(unbounded)?!

UPDATE:

int numberOfTriggers = 1024 is the upper limit where multi>1 still works.

UPDATE 2:

.groupBy(Function.identity(), Integer.MAX_VALUE) resolves the issue. Not really sure why though?!

PeMa
  • 1,559
  • 18
  • 44

0 Answers0