Skip to content

Handle multiple gRPC port registrations#54928

Open
alesj wants to merge 1 commit into
quarkusio:mainfrom
alesj:regPort1
Open

Handle multiple gRPC port registrations#54928
alesj wants to merge 1 commit into
quarkusio:mainfrom
alesj:regPort1

Conversation

@alesj

@alesj alesj commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Ignore next port registrations for multi-instance gRPC usage.

@alesj alesj requested a review from radcortez June 18, 2026 11:05
@alesj alesj requested a review from cescoffier June 18, 2026 11:05
@quarkus-bot quarkus-bot Bot added the area/grpc gRPC label Jun 18, 2026
@quarkus-bot

quarkus-bot Bot commented Jun 18, 2026

Copy link
Copy Markdown

Status for workflow Quarkus CI

This is the status report for running Quarkus CI on commit 142bab3.

✅ The latest workflow run for the pull request has completed successfully.

It should be safe to merge provided you have a look at the other checks in the summary.

You can consult the Develocity build scans.

int actualPort = grpcServer.getPort();
valueRegistry.getValue().register(GRPC_PORT, actualPort);
if (launchMode.isDevOrTest()) {
valueRegistry.getValue().register(GRPC_TEST_PORT, actualPort);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a check-and-act race condition here. You check that it's not set, and set it afterwards, without any check that it was not set in between by another thread.

It might be an API issue as it would be better to have something like: registerIfAbsent, or something like registerIfAbsent that takes a Supplier and guarantees that if would not be changed in between.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively, and much simpler: registerPort.compareAndSet(false, true)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively, and much simpler: registerPort.compareAndSet(false, true)

Where?
Since that is exactly what @radcortez said it should not be done.

I think you're right, the ValueRegistry should have the API as you said -- registerIfAbsent.
Anything else can have a race or set things before they actually work; e.g. exception is thrown, but we already set it to true.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@radcortez what's the rationale for not doing a compareAndSet?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because io.grpc.Server#getPort may return IllegalStateException if the server is not yet started.

We could do compareAndSet and reset it in the case if throw an exception.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants