Skip to content

Fix race in Naming_Tools.Register when contexts are created concurrently - #35

Open
gdepacetest wants to merge 1 commit into
AdaCore:masterfrom
gdepacetest:fix-naming-register-race
Open

gdepacetest wants to merge 1 commit into
AdaCore:masterfrom
gdepacetest:fix-naming-register-race

Conversation

@gdepacetest

Copy link
Copy Markdown

Problem

PolyORB.CORBA_P.Naming_Tools.Register fails when two processes register names under the same, not yet existing, naming context at the same time. For example, two servers register DogPark/North and DogPark/South against one po_cos_naming.

  1. Both servers call Retrieve_Context, both get NotFound from resolve, and both call bind_new_context for DogPark.
  2. The second bind_new_context raises AlreadyBound. Retrieve_Context doesn't handle it, so it propagates into Register.
  3. Register has an AlreadyBound handler around the whole procedure, meant for its own bind. It catches this exception while Context is still nil:
    • with Rebind => True, it calls rebind on the nil context and raises CORBA.INV_OBJREF;
    • with Rebind => False, it re-raises AlreadyBound for a name that was never bound.

How to reproduce

Start po_cos_naming, then start two servers at the same moment that each call:

PolyORB.CORBA_P.Naming_Tools.Register ("Parks/<unique name>", Ref, Rebind => True);

In our test (two PolyORB servers on one machine, started together), one of them failed with CORBA.INV_OBJREF from CosNaming.NamingContext.Rebind in about 7 of 10 runs:

raised CORBA.INV_OBJREF : 00000000N
Corba.Raise_Inv_Objref at corba.adb:411
Cosnaming.Namingcontext.Rebind at cosnaming-namingcontext.adb:273
Polyorb.Corba_P.Naming_Tools.Register at polyorb-corba_p-naming_tools.adb:185

Fix

  • Retrieve_Context: if bind_new_context raises AlreadyBound, another client created the context in the meantime, so resolve it again and use that context.
  • Register: the AlreadyBound handler now covers only bind (Context, N, Ref), so it only runs when the name itself is already bound.

Testing

  • PolyORB builds with its usual flags (-gnaty -gnatwae).
  • Our two-server scenario ran 20 times with no registration failure, compared with about 7 failures in 10 runs before the fix.

When two servers register names under the same new naming context at
the same time (e.g. "Parks/North" and "Parks/South"), both may find
the context missing in Retrieve_Context and call bind_new_context.
The second call raises AlreadyBound, which propagated out of
Retrieve_Context into the AlreadyBound handler of Register. With
Rebind => True, that handler then called rebind on a nil Context,
raising INV_OBJREF; with Rebind => False it re-raised a misleading
AlreadyBound for a name that was never bound.

Retrieve_Context now resolves the context again when bind_new_context
raises AlreadyBound, and Register only handles AlreadyBound raised by
its own bind.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@CLAassistant

CLAassistant commented Oct 7, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants