This is an automated email from the ASF dual-hosted git repository.
github-merge-queue[bot] pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/texera.git
The following commit(s) were added to refs/heads/main by this push:
new 4a9478c976 feat(pyamber): stop writes after upload failure (#8260)
4a9478c976 is described below
commit 4a9478c976b9496b614f2a0bfbfe2cb553566a65
Author: carloea2 <[email protected]>
AuthorDate: Wed Nov 18 23:48:03 2026 +0000
feat(pyamber): stop writes after upload failure (#8260)
### What changes were proposed in this PR?
Use timed queue writes so the producer notices a background upload
failure. Stop waiting to queue the EOF marker once the upload worker
finishes.
The writer reuses the same failure check at entry and on queue retries.
The regression covers both `write()` and `close()` with a full queue.
### Any related issues, documentation, discussions?
Closes #8259
### How was this PR tested?
The writer hangs on main when the upload fails with a full queue.
Restoring the old `close()` also hits the new five-second timeout. From
`amber` after running `bash bin/python-proto-gen.sh` from the repo root:
```bash
python -m pytest -q -m 'not integration' src/test/python/pytexera/storage
python -m ruff check src/main/python src/test/python
python -m ruff format --check src/main/python src/test/python
```
81 tests passed on Windows. Ruff lint and formatting checks passed.
### Was this PR authored or co-authored using generative AI tooling?
Generated-by: Codex
---
.../pytexera/storage/large_binary_output_stream.py | 28 +++++++++++++++------
.../storage/test_large_binary_output_stream.py | 29 ++++++++++++++++++++++
2 files changed, 49 insertions(+), 8 deletions(-)
diff --git
a/amber/src/main/python/pytexera/storage/large_binary_output_stream.py
b/amber/src/main/python/pytexera/storage/large_binary_output_stream.py
index 63d4caeb6b..2080e5a580 100644
--- a/amber/src/main/python/pytexera/storage/large_binary_output_stream.py
+++ b/amber/src/main/python/pytexera/storage/large_binary_output_stream.py
@@ -125,6 +125,12 @@ class LargeBinaryOutputStream(IOBase):
self._upload_thread: Optional[threading.Thread] = None
self._lock = threading.Lock()
+ def _raise_if_upload_failed(self) -> None:
+ with self._lock:
+ exception = self._upload_exception
+ if exception is not None:
+ raise IOError(f"Background upload failed: {exception}") from
exception
+
def write(self, b: Union[bytes, bytearray]) -> int:
"""
Write bytes to the stream.
@@ -142,12 +148,7 @@ class LargeBinaryOutputStream(IOBase):
if self.closed:
raise ValueError("I/O operation on closed stream")
- # Check if upload has failed
- with self._lock:
- if self._upload_exception is not None:
- raise IOError(
- f"Background upload failed: {self._upload_exception}"
- ) from self._upload_exception
+ self._raise_if_upload_failed()
# Start upload thread on first write
if self._upload_thread is None:
@@ -181,7 +182,13 @@ class LargeBinaryOutputStream(IOBase):
# Write data in chunks
data = bytes(b)
for offset in range(0, len(data), _CHUNK_SIZE):
- self._queue.put(data[offset : offset + _CHUNK_SIZE], block=True)
+ chunk = data[offset : offset + _CHUNK_SIZE]
+ while True:
+ try:
+ self._queue.put(chunk, timeout=_QUEUE_TIMEOUT)
+ break
+ except queue.Full:
+ self._raise_if_upload_failed()
return len(data)
@@ -221,7 +228,12 @@ class LargeBinaryOutputStream(IOBase):
try:
# Signal EOF to upload thread and wait for completion
if self._upload_thread is not None:
- self._queue.put(None, block=True) # EOF marker
+ while not self._upload_complete.is_set():
+ try:
+ self._queue.put(None, timeout=_QUEUE_TIMEOUT)
+ break
+ except queue.Full:
+ pass
self._upload_thread.join()
self._upload_complete.wait()
diff --git
a/amber/src/test/python/pytexera/storage/test_large_binary_output_stream.py
b/amber/src/test/python/pytexera/storage/test_large_binary_output_stream.py
index dc8881ab16..93f09c14c1 100644
--- a/amber/src/test/python/pytexera/storage/test_large_binary_output_stream.py
+++ b/amber/src/test/python/pytexera/storage/test_large_binary_output_stream.py
@@ -16,6 +16,7 @@
# under the License.
import queue
+import threading
import pytest
import time
from unittest.mock import patch, MagicMock
@@ -232,6 +233,34 @@ class TestLargeBinaryOutputStream:
with pytest.raises(IOError):
stream.close()
+ @pytest.mark.timeout(5)
+ def test_write_unblocks_when_upload_fails_with_full_queue(self,
large_binary):
+ with (
+ patch("pytexera.storage.large_binary_output_stream._CHUNK_SIZE",
1),
+ patch.object(large_binary_manager, "_get_s3_client") as get_client,
+ patch.object(large_binary_manager, "_ensure_bucket_exists"),
+ ):
+ get_client.return_value.upload_fileobj.side_effect = RuntimeError(
+ "upload failed"
+ )
+ stream = LargeBinaryOutputStream(large_binary)
+ errors = []
+
+ def write_chunks():
+ try:
+ stream.write(b"abc")
+ except IOError as error:
+ errors.append(error)
+
+ writer = threading.Thread(target=write_chunks, daemon=True)
+ writer.start()
+ writer.join(1)
+
+ assert not writer.is_alive()
+ assert str(errors[0]) == "Background upload failed: upload failed"
+ with pytest.raises(IOError, match="Failed to complete upload"):
+ stream.close()
+
def test_multiple_close_calls(self, large_binary):
"""Test that multiple close() calls are safe."""
with (