Skip to content

Harden SyncGroupMembersAction 4xx handling - #3299

Open
CydeWeys wants to merge 1 commit into
google:masterfrom
CydeWeys:fix-sync-group-members-4xx
Open

CydeWeys wants to merge 1 commit into
google:masterfrom
CydeWeys:fix-sync-group-members-4xx

Conversation

@CydeWeys

@CydeWeys CydeWeys commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

Prevent a single invalid registrar contact email from wedging Google Groups
contact syncing for that registrar and triggering endless scheduled-task HTTP
500 retries and duplicate SEVERE error logs, while rejecting contact emails
with invalid or misspelled TLDs up front in Registrar Console.

Previously, SyncGroupMembersAction (0ef0c933d, 262009759) wrapped each
registrar's entire sync in retrier.callWithRetry(..., RuntimeException.class),
aborted the RegistrarPoc.Type loop on the first failed email, and logged every
failure twice at SEVERE. Combined with ContactAction (db1b92638) relying
solely on Registrar.checkValidEmail() (RFC 5322 syntax without a public-suffix
check), a single contact email with a non-public-suffix TLD caused deterministic
Google Workspace Directory API HTTP 400 Invalid Input: memberKey errors that
blocked all subsequent contact groups for that registrar and repeatedly failed
with HTTP 500 across scheduled sync runs and Cloud Tasks retries.

Changes

  • DirectoryGroupsConnection & Retrier:
    • Add DirectoryGroupsConnection.isRetryableException(Throwable)
      (inspecting the full causal chain via Throwables.getCausalChain) and
      Retrier.callWithRetry(VoidCallable, Predicate<Throwable>) so
      deterministic HTTP 4xx errors (400, 401, non-rate-limit 403,
      wrapped 404 Resource Not Found: memberKey, 409) are never retried,
      while transient HTTP 5xx, 429, 403 rate-limit overages
      (rateLimitExceeded, userRateLimitExceeded, quotaExceeded), and
      non-HTTP IOExceptions remain retryable.
    • Add DirectoryGroupsConnection.isInvalidMemberException(Throwable) to
      identify deterministic member-key rejections (400 Invalid Input: memberKey / Missing required field: memberKey and 404 Resource Not Found: memberKey).
  • SyncGroupMembersAction:
    • Isolate getMembersOfGroup, addMemberToGroup, and
      removeMemberFromGroup at the per-group and per-member level so one
      failing email or group never blocks remaining contacts or groups.
    • Skip deterministic invalid/missing memberKey errors (400/404) with
      a single actionable WARNING naming (email, registrarId, groupKey) so
      valid contacts sync and contactsRequireSyncing clears when no other
      errors occur, stopping deterministic member-key errors from repeatedly
      failing the task with HTTP 500 while keeping non-member/transient
      failures returning 500 with contactsRequireSyncing = true.
    • Remove the duplicate logger.atSevere() in run() since
      Result.FAILED already logs every failure cause once at SEVERE.
  • ContactAction:
    • Guard empty request payloads and null/malformed emails before
      RegistrarPoc.Builder.build() so invalid requests return HTTP 400
      instead of 500.
    • Validate new and updated contact email domains in updateContacts and
      checkContactRequirements via UTS46 IDN canonicalization and Guava
      InternetDomainName (hasPublicSuffix() && !isPublicSuffix()),
      rejecting non-public-suffix domains (e.g. user@example.invalidtld),
      bare public suffixes (e.g. user@com, user@co.uk),
      leading/trailing/consecutive dots, underscores, multiple @, display
      names, and malformed punycode while accepting uppercase and valid
      IDN/punycode domains.

Blast Radius & Compatibility

  • CreateGroupsAction & UpdateUserGroupAction:
    DirectoryGroupsConnection.addMemberToGroup() continues to throw
    GoogleJsonResponseException on HTTP 400 so admin endpoints fail fast on
    invalid operator inputs, while preserving all existing 404/409
    idempotency behavior.
  • Synthetic Test Domains & Legacy Contacts: Public-suffix validation is
    scoped to ContactAction rather than Registrar.checkValidEmail() so
    synthetic .example/.test/.tld unit test fixtures across unrelated
    suites remain unaffected, and existing legacy invalid contacts remain
    deletable and editable (DELETE / PUT) in Console without locking
    registrars out of unrelated contact updates.

Verification

  • Added empirical regression and edge-case unit tests in
    SyncGroupMembersActionTest (log-count assertions, 400/404 memberKey
    isolation, 403 non-retry, 429/403 rate-limit retries),
    DirectoryGroupsConnectionTest (isRetryableException and
    isInvalidMemberException classification), ContactActionTest (wired
    through real ServletInputStream + RequestModule +
    ConsoleModule.provideContacts), and RetrierTest.
  • Verified ./gradlew spotlessCheck javaIncrementalFormatCheck runPresubmits :util:check :core:test (0 failures) and pr-polisher (0 errors, 0
    warnings).

BUG=http://b/590541612


This change is Reviewable

@CydeWeys
CydeWeys requested a review from weiminyu November 25, 2026 23:54
Prevent a single invalid registrar contact email from wedging Google Groups
contact syncing for that registrar and triggering endless scheduled-task HTTP
500 retries and duplicate SEVERE error logs, while rejecting contact emails
with invalid or misspelled TLDs up front in Registrar Console.

Previously, SyncGroupMembersAction (0ef0c93, 2620097) retried all
RuntimeExceptions, aborted a registrar's RegistrarPoc.Type loop on the first
failed email, and logged each failure twice at SEVERE, while ContactAction
(db1b926) accepted any syntactically valid RFC 5322 email regardless of
public suffix.

- Add DirectoryGroupsConnection.isRetryableException() and
  isInvalidMemberException(), plus Retrier.callWithRetry(VoidCallable,
  Predicate), so deterministic HTTP 4xx errors are never retried while HTTP
  5xx, 429, 403 rate-limit overages (rateLimitExceeded,
  userRateLimitExceeded, quotaExceeded), and network IOExceptions remain
  retryable. Preserve throwing on 400 in DirectoryGroupsConnection so admin
  callers (CreateGroupsAction, UpdateUserGroupAction) still fail fast.
- Isolate per-group and per-member operations in SyncGroupMembersAction so one
  failing email or group never blocks remaining contacts or groups. Skip
  deterministic invalid/missing memberKey errors (400/404) with a single
  WARNING naming the email, registrarId, and groupKey so valid contacts sync
  and contactsRequireSyncing clears instead of failing the task with HTTP 500.
- Remove duplicate logger.atSevere() in SyncGroupMembersAction.run() since
  Result.FAILED already logs every error cause once at SEVERE.
- Validate public suffixes in ContactAction (and checkContactRequirements) via
  Guava InternetDomainName and UTS46 IDN canonicalization while guarding empty
  payloads and null/malformed emails to return HTTP 400 instead of 500,
  leaving Registrar.checkValidEmail() untouched for synthetic test domains and
  allowing existing legacy invalid POCs to be deleted or corrected via
  Console.

BUG=http://b/590541612
@CydeWeys
CydeWeys force-pushed the fix-sync-group-members-4xx branch from 8562f7d to 805fb75 Compare November 26, 2026 00:14

This branch has not been deployed

No deployments
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.

1 participant