OpenFn / OpenFn/lightning

Application fails to start when external auth provider is unavailable

Open
#308 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Elixir
Stars
296
Forks
86
Avg merge
1d 13h
Merged PRs (30d)
50

Description

When starting the application, and a given Auth Provider setting (specifically the discovery url) is either incorrect or the host is not available then the application will fail to start:

** (Mix) Could not start application lightning: Lightning.Application.start(:normal, [:timex]) returned an error: shutdown: failed to start child: Cachex
    ** (EXIT) an exception was raised:
        ** (MatchError) no match of right hand side value: {:error, {:shutdown, {:failed_to_start_child, Cachex.Services.Incubator, {:shutdown, {:failed_to_start_child, Lightning.AuthProviders.CacheWarmer, {:function_clause, [{Map, :from_struct, [error: %HTTPoison.Error{id: nil, reason: :econnrefused}], [file: 'lib/map.ex', line: 946]}, {Lightning.AuthProviders.Handler, :validate_opts, 1, [file: 'lib/lightning/auth_providers/handler.ex', line: 115]}, {Lightning.AuthProviders.Handler, :new, 2, [file: 'lib/lightning/auth_providers/handler.ex', line: 38]}, {Lightning.AuthProviders.CacheWarmer, :execute, 1, [file: 'lib/lightning/auth_providers/cache_warmer.ex', line: 25]}, {Lightning.AuthProviders.CacheWarmer, :handle_info, 2, [file: 'lib/cachex/warmer.ex', line: 84]}, {Lightning.AuthProviders.CacheWarmer, :init, 1, [file: 'lib/cachex/warmer.ex', line: 72]}, {:gen_server, :init_it, 2, [file: 'gen_server.erl', line: 423]}, {:gen_server, :init_it, 6, [file: 'gen_server.erl', line: 390]}, {:proc_lib, :init_p_do_apply, 3, [file: 'proc_lib.erl', line: 226]}]}}}}}}
            (cachex 3.4.0) lib/cachex.ex:301: Cachex.start_link/1
            (stdlib 3.17) supervisor.erl:414: :supervisor.do_start_child_i/3
            (stdlib 3.17) supervisor.erl:400: :supervisor.do_start_child/2
            (stdlib 3.17) supervisor.erl:384: anonymous fn/3 in :supervisor.start_children/2
            (stdlib 3.17) supervisor.erl:1250: :supervisor.children_map/4
            (stdlib 3.17) supervisor.erl:350: :supervisor.init_children/2
            (stdlib 3.17) gen_server.erl:423: :gen_server.init_it/2
            (stdlib 3.17) gen_server.erl:390: :gen_server.init_it/6
            (stdlib 3.17) proc_lib.erl:226: :proc_lib.init_p_do_apply/3

Expected behavior

In the case of an unavailable provider, we need to fail gracefully with a warning.

Additional context

We have discussed previously, to only use the discovery url as a way to seed the endpoint urls - but taking this approach we won't be exposed to this kind of error scenario.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading lib/lightning/auth_providers/handler.ex and lib/lightning/auth_providers/cache_warmer.ex, then reproduce startup with an unavailable or invalid discovery URL. Trace how the HTTPoison error reaches validation and confirm that startup completes with a warning instead of failing the Cachex child.

Written by the indexing model from the issue text.

Assessment

Tech stack
elixir
Domain
authentication, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.