Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clicking the Sign In link via local adapter causes Beam.smp to max out my CPU #27

Open
That-David-Guy opened this issue Aug 25, 2020 · 3 comments

Comments

@That-David-Guy
Copy link

Hi

Locally, the following happens:

  1. Click sign in
  2. fill out sign in form, e.g. test@test.com
  3. go to dev/mailbox
  4. click 'Open preview in separate tab`
  5. Click 'Sign In'
  6. I've sign in to my app, BUT I also notice that my CPU process 'beam.smp' jumps to 100+% and stays there.

I was expecting my CPU not to jump at all.

No other action on my site seems to cause a CPU spike.

I'm not even sure how to go about debugging this? Do you have any ideas?

I'm following this blog post https://elixircasts.io/passwordless-authentication-with-veil .

My config.exs file:

# //

# -- Veil Configuration    Don't remove this line
config :veil,
  site_name: "makeawesomeworkshop",
  email_from_name: "David Langford",
  email_from_address: "davidlangford@hey.com",
  sign_in_link_expiry: 12 * 3_600, # How long should emailed sign-in links be valid for?
  session_expiry: 86_400 * 30, # How long should sessions be valid for?
  refresh_expiry_interval: 86_400,  # How often should existing sessions be extended to session_expiry
  sessions_cache_limit: 250, # How many recent sessions to keep in cache (to reduce database operations)
  users_cache_limit: 100 # How many recent users to keep in cache

config :veil, Veil.Scheduler,
  jobs: [
    # Runs every midnight to delete all expired requests and sessions
    {"@daily", {Maw.Veil.Clean, :expired, []}}
  ]

# This is in dev.config and prod.secrect.config ~ David
# config :veil, MawWeb.Veil.Mailer,
#   adapter: Swoosh.Adapters.Sendgrid,
#   api_key: "your-api-key"

# -- End Veil Configuration

My config/dev.exs file

# //

# Passwordless Authentication
config :veil, MawWeb.Veil.Mailer,
  adapter: Swoosh.Adapters.Local

# //

My mix.exs file:

      elixir: "~> 1.5",
 {:phoenix, "~> 1.4.3"},
{:veil, github: "zanderxyz/veil"},
  def project do
    [
      app: :maw,
      version: "0.1.0",
      elixir: "~> 1.5",
      elixirc_paths: elixirc_paths(Mix.env()),
      compilers: [:phoenix, :gettext] ++ Mix.compilers(),
      start_permanent: Mix.env() == :prod,
      aliases: aliases(),
      deps: deps()
    ]
  end

  def application do
    [
      mod: {Maw.Application, []},
      extra_applications: [:logger, :runtime_tools]
    ]
  end

  defp elixirc_paths(:test), do: ["lib", "test/support"]
  defp elixirc_paths(_), do: ["lib"]

  defp deps do
    [
      {:bamboo, "~> 1.5"},
      {:phoenix, "~> 1.4.3"},
      {:phoenix_pubsub, "~> 1.1"},
      {:phoenix_ecto, "~> 4.0"},
      {:ecto_sql, "~> 3.0"},
      {:postgrex, ">= 0.0.0"},
      {:phoenix_html, "~> 2.11"},
      {:phoenix_live_reload, "~> 1.2", only: :dev},
      {:gettext, "~> 0.11"},
      {:jason, "~> 1.0"},
      {:plug_cowboy, "~> 2.0"},
      # Passwordless Authentication
      {:veil, github: "zanderxyz/veil"},
      # Waffle stuff below
      {:waffle, "~> 1.1.1"},
      {:ex_aws, "~> 2.1.2"},
      {:ex_aws_s3, "~> 2.0"},
      {:hackney, "~> 1.9"},
      {:sweet_xml, "~> 0.6"},
      {:waffle_ecto, "~> 0.0.9"}
      # Waffle stuff above
    ]
  end

  defp aliases do
    [
      "ecto.setup": ["ecto.create", "ecto.migrate", "run priv/repo/seeds.exs"],
      "ecto.reset": ["ecto.drop", "ecto.setup"],
      test: ["ecto.create --quiet", "ecto.migrate", "test"],
      releases: releases()
    ]
  end

  defp releases() do
    [
      hexpm: [
        include_executables_for: [:unix]
      ]
    ]
  end
@That-David-Guy
Copy link
Author

If I comment out this line in session_controller.ex the CPU will not spike

# session_controller.ex file

  def create(conn, %{"request_id" => request_unique_id}) do
     # --
              # Commenting out the below line STOPS the CPU spiking
              Task.start(fn -> Veil.verify_user(user_id) end)
    # --

@That-David-Guy
Copy link
Author

And checking the database, it looks like my user never actually verifies (the value in the verified column is FALSE)

@technicalcapt
Copy link

@That-David-Guy If you check on verify_user function, the return value from Cachex wasn't correct.

def verify_user(user_id) do
    case get_user(user_id) do
      {:ok, user} ->  # <-- change user to {:ok, user} it will fix the issue with verifying user and resolve the process trap error.
        verify_user(user)

      error ->
        error
    end
  end

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

No branches or pull requests

2 participants