ex-aws / ex_aws

A flexible, easy to use set of clients AWS APIs for Elixir
https://hex.pm/packages/ex_aws
MIT License
1.26k stars 521 forks source link

process attempted to call itself #948

Open kxkannan opened 1 year ago

kxkannan commented 1 year ago

Environment

Current behavior

Include code samples, errors and stacktraces if appropriate.

2023-04-21T16:22:42.458 [error] mfa=:gen_server.error_info/8 pid=<0.4531.0>  GenServer ExAws.Config.AuthCache terminating
** (stop) exited in: GenServer.call(ExAws.Config.AuthCache, {:refresh_awscli_config, "stx-in-nonprod", 30000}, 30000)
    ** (EXIT) process attempted to call itself
    (elixir 1.14.4) lib/gen_server.ex:1031: GenServer.call/3
    (ex_aws 2.4.2) lib/ex_aws/config.ex:181: ExAws.Config.retrieve_runtime_value/2
    (elixir 1.14.4) lib/stream.ex:612: anonymous fn/4 in Stream.map/2
    (elixir 1.14.4) lib/enum.ex:4751: Enumerable.List.reduce/3
    (elixir 1.14.4) lib/stream.ex:1813: Enumerable.Stream.do_each/4
    (elixir 1.14.4) lib/enum.ex:1150: Enum.find/3
    (ex_aws 2.4.2) lib/ex_aws/config.ex:162: anonymous fn/2 in ExAws.Config.retrieve_runtime_config/1
    (stdlib 4.3) maps.erl:411: :maps.fold_1/3
    (ex_aws 2.4.2) lib/ex_aws/config.ex:70: ExAws.Config.new/2
    (ex_aws 2.4.2) lib/ex_aws.ex:73: ExAws.request/2
    (ex_aws_sts 2.3.0) lib/ex_aws/sts/auth_cache/assume_role_credentials_adapter.ex:36: ExAws.STS.AuthCache.AssumeRoleCredentialsAdapter.get_security_credentials/3
    (ex_aws 2.4.2) lib/ex_aws/config/auth_cache.ex:83: ExAws.Config.AuthCache.attempt_credentials_refresh/5
    (ex_aws 2.4.2) lib/ex_aws/config/auth_cache.ex:73: ExAws.Config.AuthCache.refresh_awscli_config/3
    (ex_aws 2.4.2) lib/ex_aws/config/auth_cache.ex:50: ExAws.Config.AuthCache.handle_call/3
    (stdlib 4.3) gen_server.erl:1149: :gen_server.try_handle_call/4
    (stdlib 4.3) gen_server.erl:1178: :gen_server.handle_msg/6
    (stdlib 4.3) proc_lib.erl:240: :proc_lib.init_p_do_apply/3
Last message (from #PID<0.5004.0>): {:refresh_awscli_config, "stx-in-nonprod", 30000}
2023-04-21T16:22:42.467 [error] mfa=:gen_server.error_info/8 pid=<0.5004.0>  GenServer #PID<0.5004.0> terminating

Expected behavior

This error shouldn't appear.

Used to work until I updated to Elixir 1.14.4 and Erlang 25.3.

kxkannan commented 1 year ago

FYI, this seems to happen in release 2.4.2. I don't see this error in 2.4.1

geofflane commented 1 year ago

Saw this trying to use ex_aws_sts for assumed role access. During the call to case adapter.adapt_auth_config(auth, profile, expiration) do the plugin initiates a new request which attempts to access the Genserver again. That is a deadlock and so fails.

That still happens in 2.4.1 as well though. That seems like a fundamental problem with the assumed role authentication use case.

e.g.

config :ex_aws,
  secret_access_key: [{:awscli, "fb2b_staging", 30}],
  access_key_id: [{:awscli, "fb2b_staging", 30}],
  awscli_auth_adapter: ExAws.STS.AuthCache.AssumeRoleCredentialsAdapter,
  awscli_credentials: %{
    "default" => %{
      secret_access_key: [{:awscli, "default", 30}],
      access_key_id: [{:awscli, "default", 30}],
    },
    "fb2b_staging" => %{
      role_arn: "arn:aws:iam::xxxxxxx:role/fb2b-developer-role",
      source_profile: "default"
    }
  }
bernardd commented 1 year ago

Thanks for the report. This one's gonna need some thinking - the short version is that the the auth cache is trying to update itself which is triggering a request which is (for some reason) trying to get credentials by calling the auth cache. I'm going to have to do some digging to figure out exactly what the right solution is.

blimmer commented 6 months ago

Linking this up with https://github.com/ex-aws/ex_aws_sts/issues/35, the issue on the ex_aws_sts plugin page