nats-io/nats-server · error

service import not found

Error message

service import not found

What it means

Returned when no service import entry matches the given destination account name and 'to' subject (server/accounts.go:1819). setServiceImportSharing scans the account's service imports and fails if none match.

Source

Thrown at server/accounts.go:1819

// setServiceImportSharing will allow sharing of information about requests with the export account.
func (a *Account) setServiceImportSharing(destination *Account, to string, check, allow bool) error {
	a.mu.Lock()
	defer a.mu.Unlock()
	if check && a.isClaimAccount() {
		return fmt.Errorf("claim based accounts can not be updated directly")
	}
	// We can't use getServiceImportForAccountLocked() here since we are looking
	// for the service import with the si.to == to, which may not be the key
	// for the service import in the map.
	for _, sis := range a.imports.services {
		for _, si := range sis {
			if si.acc.Name == destination.Name && si.to == to {
				si.share = allow
				return nil
			}
		}
	}
	return fmt.Errorf("service import not found")
}

// AddServiceImport will add a route to an account to send published messages / requests
// to the destination account. From is the local subject to map, To is the
// subject that will appear on the destination account. Destination will need
// to have an import rule to allow access via addService.
func (a *Account) AddServiceImport(destination *Account, from, to string) error {
	return a.AddServiceImportWithClaim(destination, from, to, nil)
}

// NumPendingReverseResponses returns the number of response mappings we have for all outstanding
// requests for service imports.
func (a *Account) NumPendingReverseResponses() int {
	a.mu.RLock()
	defer a.mu.RUnlock()
	return len(a.imports.rrMap)
}

View on GitHub (pinned to 3a66a489d2)

Solutions

  1. Verify the service import exists: call AddServiceImport before changing sharing settings.
  2. Check the exact 'to' subject and destination account name used at import time.
  3. Iterate the account's imports.services to confirm the matching entry.

Example fix

// before
acc.setServiceImportSharing(destAcc, "WRONG_SUBJECT", true, true)
// after
acc.AddServiceImport(destAcc, "req", "help.request")
acc.setServiceImportSharing(destAcc, "help.request", true, true)
Defensive patterns

Strategy: validation

Validate before calling

// confirm the import exists before sharing changes
found := false
for _, sis := range acc.imports.services {
    for _, si := range sis {
        if si.acc.Name == dest.Name && si.to == to { found = true }
    }
}
if !found { return errors.New("no matching service import") }

Try / catch

if err := acc.setServiceImportSharing(dest, to, true, true); err != nil {
    if strings.Contains(err.Error(), "service import not found") {
        // call AddServiceImport first
    }
}

Prevention

When it happens

Trigger: Calling setServiceImportSharing with a destination account name or 'to' subject that does not match an existing service import on the account.

Common situations: Typo in the 'to' subject, calling sharing update before AddServiceImport was ever called, or destination account name mismatch after account recreation.

Related errors


AI-assisted analysis of nats-io/nats-server@3a66a489d2 (2026-09-02). Data as JSON: /api/errors/1f1eb942fea3a86b. Report an issue: GitHub.