damccorm opened a new pull request, #41129:
URL: https://github.com/apache/beam/pull/41129

   ### Summary
   Fixes container startup retry handling in 
`SQLEnrichmentTestHelper.start_sql_db_container` 
(`sdks/python/apache_beam/transforms/enrichment_handlers/cloudsql_it_test.py`) 
and `MilvusTestHelpers.start_db_container` 
(`sdks/python/apache_beam/ml/rag/test_utils.py`), observed in `PostCommit 
Python Versions` 
([#42647458373](https://github.com/apache/beam/actions/runs/42647458373)).
   
   ### Root Cause
   In [#42647458373](https://github.com/apache/beam/actions/runs/42647458373), 
`sql_db_container.start()` timed out inside `Reaper.get_instance()` while 
creating the Ryuk container (`testcontainers-ryuk-<session_id>`) before 
`sql_db_container._container` or `Reaper._instance` was assigned:
   1. The `except Exception as e:` handler unconditionally called 
`sql_db_container.get_logs()`, which immediately raised 
`ContainerStartException('Container should be started before getting logs')` on 
attempt `i = 0`, aborting the `for i in range(sql_client_retries):` retry loop 
without retrying.
   2. Because Docker had already created `testcontainers-ryuk-<session_id>` 
before the read timeout occurred while `Reaper._instance` remained `None`, 
every subsequent container start in the same pytest worker 
(`TestExternalMySQLEnrichment` and `TestExternalSQLServerEnrichment`) failed 
with `409 Client Error: Conflict ('The container name 
"/testcontainers-ryuk-..." is already in use')`.
   
   ### Fix
   1. Guard `get_logs()` (and `stop()`) on `getattr(container, '_container', 
None) is not None` inside `try ... except Exception:` so pre-start exceptions 
do not abort the retry loop.
   2. When `getattr(Reaper, '_instance', None) is None`, remove any orphaned 
`testcontainers-ryuk-<session_id>` container belonging to the current session 
(`x-tc-sid`) so the next retry cleanly initializes Ryuk.
   
   ### Verification
   - Triggered `PostCommit Python Versions` workflow run on branch: 
[`42665122826`](https://github.com/apache/beam/actions/runs/42665122826)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to