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 crash on repeated MockWebServer shutdown #5672

Merged
merged 1 commit into from
Dec 31, 2019

Conversation

swankjesse
Copy link
Collaborator

The problem was the awaitIdle() call was scheduling executor jobs after
the ExecutorService had been shut down. This fixes that and defends
against other races.

The problem was the awaitIdle() call was scheduling executor jobs after
the ExecutorService had been shut down. This fixes that and defends
against other races.
@swankjesse swankjesse force-pushed the jwilson.1230.await_idle branch from 5567730 to edb5865 Compare December 31, 2019 04:35

@Test fun idleLatchAfterShutdown() {
queue.schedule("task") {
Thread.sleep(250)
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: on it's own 250ms is fine. As part of a test suite 40 tests taking this approach add 10 seconds to running the tests and is still more flaky then using e.g. CountDownLatch here.

I've raised #5673 to fix such usages.

if (existingTask is AwaitIdleTask) {
return existingTask.latch
}
for (futureTask in futureTasks) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not sure about practically, but do you need to check anything but the last task here? If it's non empty and has other tasks, seems by definition it's not idle.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think at the edges I’m conflating two concepts:

  • idle: nothing running, nothing scheduled
  • flush: complete all currently-enqueued tasks

In practice they’re the same effect for us, but I’ve implemented flush and labeled it idle. Because true idle is more work to implement for academic benefit I’m going to leave it as-is for now. Unsatisfying!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

One other wrench here . . . idle is distinct from shutdown. For example in our test suite we enforce idleness between tests, but share the same task runner between tests.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hopefully this is still a remaining cause of when our tests fail they tend to be flaky in batches, and we can fix a few remaining issues and have it rock solid.

Overall - trending ok https://circleci.com/build-insights/gh/square/okhttp/master

But big room for improvements once the base is solid.

@swankjesse swankjesse merged commit b9e0422 into master Dec 31, 2019
@swankjesse swankjesse deleted the jwilson.1230.await_idle branch January 1, 2020 19:42
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