Skip to content

Concurrency issues when adding labels to an issue/PR #1049

@gsmet

Description

@gsmet

Hi,

Some context: we are using the Hub4j GitHub API for our Quarkus Bot (it's a GitHub App based on Quarkus and running as a GraalVM native executable).

The bot can automatically add labels based on triage rules but we started seeing concurrency issues when someone adds labels when the bot is also adding some. Believe it or not, this happened in real life.

AFAICS, the issue is that the GHIssue#addLabels() method doesn't really add the labels but set them. My understanding is that it should use this method: https://docs.github.com/en/rest/reference/issues#add-labels-to-an-issue and that's not what is done here:

private void _addLabels(Collection<String> names) throws IOException {
List<String> newLabels = new ArrayList<String>();
for (GHLabel label : getLabels()) {
newLabels.add(label.getName());
}
for (String name : names) {
if (!newLabels.contains(name)) {
newLabels.add(name);
}
}
setLabels(newLabels.toArray(new String[0]));
}
: you set the labels based on the existing ones + the added ones instead of adding them, which can result in data loss if you're not lucky.

The issue occurs when a label is added manually in the UI between the call at line 365 and the call at line 373: the labels added in the UI are lost, which is very unfortunate given they are critical to our workflow. You can see an example of this issue here: quarkusio/quarkus#15402 (comment) - Georgios added the triage/backport? label in the UI and the bot removed it while our bot is only adding labels.

Does it make any sense? Any chance this could be fixed?

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions