[Fix] Raise on undelivered embeddings in send_with_url, fix broken tests (#40502)
This commit is contained in:
@@ -2313,10 +2313,13 @@ class MMEncoder:
|
||||
start_time = asyncio.get_running_loop().time()
|
||||
timeout = self.send_timeout
|
||||
cond = await _get_receive_condition(req_id)
|
||||
failure: Optional[str] = None
|
||||
failure_code = HTTPStatus.BAD_GATEWAY
|
||||
|
||||
try:
|
||||
while True:
|
||||
if state.release_requested:
|
||||
# An upstream abort, not a delivery failure.
|
||||
break
|
||||
|
||||
async with rid_lock:
|
||||
@@ -2345,9 +2348,11 @@ class MMEncoder:
|
||||
break
|
||||
remaining = timeout - (asyncio.get_running_loop().time() - start_time)
|
||||
if remaining <= 0:
|
||||
logger.error(
|
||||
f"[{req_id}] Timeout! Sent {len(sent_urls)}/{expected_count}"
|
||||
failure = (
|
||||
f"timed out after {timeout}s with "
|
||||
f"{len(sent_urls)}/{expected_count} destination(s) initiated"
|
||||
)
|
||||
failure_code = HTTPStatus.GATEWAY_TIMEOUT
|
||||
break
|
||||
|
||||
async with cond:
|
||||
@@ -2363,13 +2368,25 @@ class MMEncoder:
|
||||
tasks_only = [t[0] for t in all_tasks]
|
||||
results = await asyncio.gather(*tasks_only, return_exceptions=True)
|
||||
|
||||
# Process results and log errors
|
||||
failed = []
|
||||
for i, result in enumerate(results):
|
||||
url = all_tasks[i][1] # Retrieve URL associated with the task
|
||||
if isinstance(result, Exception):
|
||||
logger.error(f"Failed to send to {url}: {result}")
|
||||
# A cancelled send delivered nothing, and CancelledError
|
||||
# is not an Exception; outer cancellation re-raises out of
|
||||
# gather rather than landing here.
|
||||
if isinstance(result, BaseException):
|
||||
logger.error(f"Failed to send to {url}: {result!r}")
|
||||
failed.append(url)
|
||||
else:
|
||||
logger.debug(f"Successfully sent to {url}")
|
||||
if failed and failure is None:
|
||||
failure = f"delivery failed for {failed}"
|
||||
|
||||
if failure is not None:
|
||||
raise MMError(
|
||||
f"[{req_id}] embedding delivery failed: {failure}",
|
||||
code=failure_code,
|
||||
)
|
||||
|
||||
logger.info(f"All tasks completed for req_id: {req_id}")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user