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

fix: Buffer.addPending sets writeRequired #1015

Merged
merged 1 commit into from
Oct 25, 2023
Merged

Conversation

leviramsey
Copy link
Contributor

require(pending.isEmpty, "Pending should be empty if write not required")

suggests that an invariant of journal.Buffer is that writeRequired || pending.nonEmpty. The addPending method, if called on a Buffer where writeRequired is false will break this invariant, which may cause subsequent adds to the buffer to throw, crashing the TagWriter and forcing an ActorSystem restart.

```scala
require(pending.isEmpty, "Pending should be empty if write not required")
```

suggests that an invariant of `journal.Buffer` is that `writeRequired || pending.nonEmpty`.  The `addPending` method, if called on a `Buffer` where `writeRequired` is `false` will break this invariant, which may cause subsequent adds to the buffer to throw, crashing the `TagWriter` and forcing an `ActorSystem` restart.
@@ -107,7 +107,7 @@ private[akka] case class Buffer(
}

final def addPending(write: AwaitingWrite): Buffer = {
copy(size = size + write.events.size, pending = pending :+ write)
copy(size = size + write.events.size, pending = pending :+ write, writeRequired = true)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems innocent and correct but difficult to see the full consequences. Tests are failing.

I looked at other places where we add to pending and then it's indeed writeRequired = true aside from rebuild. Maybe it's always set to true in rebuild also via the add but that is not immediately obvious.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the case of rebuild, it starts empty, then repeatedly adds, so anything in pending after the repeated adds came via add.

I haven't yet looked through the test failures to see what they should be.

@patriknw
Copy link
Member

close-open to run ci again

@patriknw patriknw closed this Oct 24, 2023
@patriknw patriknw reopened this Oct 24, 2023
@patriknw
Copy link
Member

Two successful runs in CI.

@patriknw patriknw merged commit ef95315 into akka:main Oct 25, 2023
4 of 5 checks passed
@patriknw patriknw added this to the 1.2.0 milestone Oct 25, 2023
@leviramsey leviramsey deleted the patch-1 branch October 25, 2023 15:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants