Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Concurrent Confluent CLI processes can read an inconsistent config.json file #2622

Open
gphilipp opened this issue Feb 15, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@gphilipp
Copy link

I have this shell script which uses the Confluent CLI to delete all subjects in a concurrent fashion:

#!/usr/bin/env bash
delete_subject() {
    echo "Soft deleting subject $1"
    confluent schema-registry schema delete --force --version all --subject "$1"
    echo "Hard deleting subject $1"
    confluent schema-registry schema delete --force --permanent --version all --subject "$1"

}

subjects=$(confluent schema-registry schema list -o json | jq -r ".[].subject")

# Perform deletes in parallel
for subject in ${subjects}; do
    delete_subject "$subject" &
    sleep 0.2
done
wait

echo "All subjects deleted."

It works most of the time, but I sometimes get these error messages:

Successfully soft deleted all versions for subject "insurance_customer_activity-value".
  Version  
-----------
        1  
Successfully soft deleted all versions for subject "payment_transaction-value".
  Version  
-----------
        1  
Hard deleting subject shoestore_clickstream-value
Successfully hard deleted all versions for subject "gaming_player-value".
  Version  
-----------
        2  
Hard deleting subject shoestore_shoe-value
Hard deleting subject fleetmgmt_location-value
Error: unable to read configuration file "/Users/gphilippart/.confluent/config.json": invalid character ']' after top-level value
Hard deleting subject pizzastore_order_cancelled-value
Hard deleting subject insurance_customer_activity-value
Error: unable to read configuration file "/Users/gphilippart/.confluent/config.json": invalid character ']' after top-level value
Error: unable to read configuration file "/Users/gphilippart/.confluent/config.json": invalid character ']' after top-level value
Error: unable to read configuration file "/Users/gphilippart/.confluent/config.json": invalid character ']' after top-level value
Hard deleting subject payment_transaction-value

What is probably happening is that another process reads the config.json file in the middle of the config write operation.
It would be best to write the config.json changes in a temporary file and then renaming it, which is an atomic operation at the OS level.

@brianstrauch brianstrauch added the bug Something isn't working label Feb 16, 2024
@brianstrauch
Copy link
Member

brianstrauch commented Jun 25, 2024

While the team works on support for running the Confluent CLI in parallel, my recommendation would be to use a separate configuration file for each thread running stateful Confluent CLI commands. You can change the path of the configuration file by prefixing commands with HOME=<tmpdir>, so each configuration file will live at a different <tmpdir>/.confluent/config.json.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants