PubSub: Release the state lock before calling the publish api #8234
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #8036.
Supersedes #7686 (the fix here is essentially the same, but also adds tests and a few minor things).
Summary
This PR makes sure that calls to
publisher.publish()
are not unnecessarily blocked while the underlying API publish call is in progress - the latter can take a substantial amount of time, especially on network errors when retries kick in.Description
The fix makes sure that the lock in the
_commit()
method is held for no longer than necessary. The details on why releasing the lock earlier is fine are listed in the comment on the original PR.How to test
Steps to reproduce:
Actual result (before the fix):
The message "Returned from second call to publish" appears in the logs only after a minute or so after the "About to publish the second message".
Expected result (after the fix):
The second message is logged shortly after the first one. The second call to
publisher.publish()
is not blocked while publishing the first message is in progress and hitting the automatic retry because of the network error.