amandayclee opened a new pull request, #22500:
URL: https://github.com/apache/kafka/pull/22500

   `generate_cluster_json_file` in `tests/docker/ducker-ak` uses `exec 3<> 
"${path}"` to open the file before writing the JSON. The `<>` form opens the 
file for read+write without clearing it first. So when this function runs a 
second time and the new content is shorter than what was already in the file, 
the leftover bytes from the previous run stay at the end. The result is a 
`cluster.json` that looks like valid JSON followed by garbage, and ducktape 
can't parse it.
   
   This happens in practice when we run `ducker_up` with fewer nodes than the 
previous run.
   
   ### Verification
   Step 1: bring up a cluster of 5 so `cluster.json` exists with a known size:
   ```bash
   ./gradlew clean systemTestLibs
   tests/docker/ducker-ak up -n 5
   stat -f '%z bytes' tests/docker/build/cluster.json
   # 1965 bytes
   ```
   
   Step 2: in the buggy version, then rewrite the same file with fewer nodes:
   ```
   bash -c '
     source <(sed -n "512,562p" tests/docker/ducker-ak)
     generate_cluster_json_file 3 tests/docker/build/cluster.json
   '
   
   stat -f '%z bytes' tests/docker/build/cluster.json
   # 1965 bytes (unchanged — stale tail)
   
   python3 -c "import json; json.load(open('tests/docker/build/cluster.json'))"
   # json.decoder.JSONDecodeError: Extra data (The file size did not shrink, 
and the JSON is invalid)
   ```
   
   Step 3: in fixed bersion and run the same write again:
   ```
   bash -c '
     source <(sed -n "512,562p" tests/docker/ducker-ak)
     generate_cluster_json_file 3 tests/docker/build/cluster.json
   '
   stat -f '%z bytes' tests/docker/build/cluster.json
   # 1429 bytes  (correctly truncated)
   
   python3 -c "import json; json.load(open('tests/docker/build/cluster.json'))"
   # (no output — valid JSON)
   
   The file shrinks from 1965 → 1429 bytes and parses cleanly.
   ```


-- 
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