t8y2/dbx · error

Cannot %s user '%s' while connected as that user

Error message

Cannot %s user '%s' while connected as that user

What it means

Deleting (or otherwise acting on) the very user the driver's connection authenticates as would cut off the connection and can lock out management access. The driver guards against createUser/deleteUser self-targeting.

Source

Thrown at agents/drivers/rabbitmq/operations.go:853

	if err != nil {
		return nil, err
	}
	connection, err := s.requireConnectionConfig(params)
	if err != nil {
		return nil, err
	}
	if err := assertNotConnectedUser("delete", name, stringOrDefault(connection, "username", "guest")); err != nil {
		return nil, err
	}
	if _, err := managementSend(connection, http.MethodDelete, "/api/users/"+urlEncodePathSegment(name), nil); err != nil {
		return nil, err
	}
	return okResult(), nil
}

func assertNotConnectedUser(action, name, connectedUser string) error {
	if name == connectedUser {
		return fmt.Errorf("Cannot %s user '%s' while connected as that user", action, name)
	}
	return nil
}

func (s *server) listPermissions(params jsonObject) (any, error) {
	connection, err := s.requireConnectionConfig(params)
	if err != nil {
		return nil, err
	}
	permissions, err := managementGet(connection, "/api/permissions")
	if err != nil {
		return nil, err
	}
	array, ok := permissions.([]any)
	if !ok {
		return nil, errors.New("Unexpected management API response for permission listing")
	}
	vhostFilter := stringOrEmpty(params, "virtual_host")

View on GitHub (pinned to c0390bff16)

Solutions

  1. Perform user management with a different administrative user than the target
  2. Reorder operations: create the new user first, switch the connection to it, then delete the old one
  3. Skip the operation when the target equals the connection username in your orchestration logic

Example fix

// before
await client.deleteUser({"name": "admin"}) // connected as admin
// after
await client.connectUser({"username": "provisioner", "password": "..."})
await client.deleteUser({"name": "admin"})
Defensive patterns

Strategy: try-catch

Validate before calling

if (targetUser === currentConnection.username) {
  throw new Error(`connect as a different user before acting on '${targetUser}'`)
}

Try / catch

try {
  await client.deleteUser({ name })
} catch (e) {
  if (String(e.message).includes("while connected as that user")) {
    await client.connectUser({ username: "provisioner", password: provisionerPw })
    await client.deleteUser({ name })
  } else { throw e }
}

Prevention

When it happens

Trigger: Calling createUser or deleteUser with a name equal to the connection config's username (connectedUser), e.g. deleting 'admin' while connected as 'admin'.

Common situations: Idempotent provisioning scripts that always run a delete-then-create for the user they connect with, test resets using the same admin user, wrong parameter ordering passing the connection user instead of the target user.

Related errors


AI-assisted analysis of t8y2/dbx@c0390bff16 (2026-09-05). Data as JSON: /api/errors/a2ca93048c0432ba. Report an issue: GitHub.