pjfanning opened a new pull request, #2762: URL: https://github.com/apache/pekko/pull/2762
Relates to #2760 Fix suggested by @diegovallone When restarting a `ProducerController` backed by a durable queue where all prior messages were confirmed (empty unconfirmed buffer), the controller immediately crashes with `IllegalStateException: Unexpected Msg when no demand`. Two hardcoded sequence number bugs in `ProducerControllerImpl.scala` are the cause. ## Bugs fixed - **`createState`**: `requestedSeqNr` was hardcoded to `1L` instead of `loadedState.currentSeqNr`. When restored `currentSeqNr` (e.g. `5`) exceeds `requestedSeqNr` (`1`), `checkOnMsgRequestedState()` throws. - **`becomeActive`**: When `unconfirmed.isEmpty`, `RequestNext` and the flight recorder were sent hardcoded `1L`/`0L` instead of the restored sequence numbers — mismatching the internal state and triggering the crash when the producer responds. ## Fix ```scala // createState requestedSeqNr = loadedState.currentSeqNr, // was: 1L // becomeActive (unconfirmed.isEmpty branch) flightRecorder.producerRequestNext(producerId, state.currentSeqNr, state.confirmedSeqNr) state.producer ! RequestNext(producerId, state.currentSeqNr, state.confirmedSeqNr, msgAdapter, context.self) // were: 1L, 0L ``` ## Test Adds `"resume correctly after restart with empty unconfirmed buffer"` to `DurableProducerControllerSpec`: loads durable state with `currentSeqNr=5`, `highestConfirmedSeqNr=4`, empty unconfirmed; asserts `RequestNext.currentSeqNr == 5` and message delivery at `seqNr=5` without crash. The test fails without the fix. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
