Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Race conditions and performance issues (#237)
* fix: Race conditions and performance issues There are two main retrying_connection race conditions fixed here: 1) Improper handling of cancelled write tasks can cause set_exception to be called when the task is already cancelled, which raises an InvalidStateError which is never caught by the existing code. 2) There is a race where if reinitialize() is called after queues are cycled, meaning a poller from the old instance of the class can add a message to the new queues. This has been fixed by splitting the ConnectionReinitializer interface into "stop_processing" and "reinitialize" parts. Also fix other performance issues identified in profiles. * fix: Race conditions and performance issues There are two main retrying_connection race conditions fixed here: 1) Improper handling of cancelled write tasks can cause set_exception to be called when the task is already cancelled, which raises an InvalidStateError which is never caught by the existing code. 2) There is a race where if reinitialize() is called after queues are cycled, meaning a poller from the old instance of the class can add a message to the new queues. This has been fixed by splitting the ConnectionReinitializer interface into "stop_processing" and "reinitialize" parts. Also fix other performance issues identified in profiles.
- Loading branch information
1 parent
90d2b58
commit ec76272
Showing
10 changed files
with
155 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
google/cloud/pubsublite/cloudpubsub/internal/sorted_list.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from typing import Generic, TypeVar, List, Optional | ||
import heapq | ||
|
||
_T = TypeVar("_T") | ||
|
||
|
||
class SortedList(Generic[_T]): | ||
_vals: List[_T] | ||
|
||
def __init__(self): | ||
self._vals = [] | ||
|
||
def push(self, val: _T): | ||
heapq.heappush(self._vals, val) | ||
|
||
def peek(self) -> Optional[_T]: | ||
if self.empty(): | ||
return None | ||
return self._vals[0] | ||
|
||
def pop(self): | ||
heapq.heappop(self._vals) | ||
|
||
def empty(self) -> bool: | ||
return not bool(self._vals) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.