-
Notifications
You must be signed in to change notification settings - Fork 583
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix possible data corruption due to race condition in StreamRedirector (
#1773) * fix: StreamRedirector may cause data corruption due to race condition Signed-off-by: Yen-Nan (Maso) Lin <[email protected]> Signed-off-by: Maso Lin <[email protected]> * fix: formating error Signed-off-by: Maso Lin <[email protected]> * fix: type checking fails Signed-off-by: Maso Lin <[email protected]> * Set explicit 10s deadline for test_stream_redirector_race_condition --------- Signed-off-by: Yen-Nan (Maso) Lin <[email protected]> Signed-off-by: Maso Lin <[email protected]> Co-authored-by: Maso Lin <[email protected]>
- Loading branch information
Showing
3 changed files
with
60 additions
and
10 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
17 changes: 17 additions & 0 deletions
17
python/tests/server/fixtures/stream_redirector_race_condition.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,17 @@ | ||
from cog import BasePredictor | ||
import threading | ||
|
||
|
||
def keep_printing(): | ||
for _ in range(10000): | ||
print("hello") | ||
|
||
|
||
class Predictor(BasePredictor): | ||
def setup(self): | ||
self.print_thread = threading.Thread(target=keep_printing) | ||
|
||
def predict(self) -> str: | ||
self.print_thread.start() | ||
output = "output" * 100000 # bigger output increases the chance of race condition | ||
return output |
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