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

Fix config options merging #111

Merged
merged 3 commits into from
Feb 23, 2024
Merged

Fix config options merging #111

merged 3 commits into from
Feb 23, 2024

Conversation

moogle19
Copy link
Contributor

Currently the user_options could overwrite the @hardcoded_options but not the default_options (gen_tcp seems to take the last option if multiple values for 1 key are defined).

This fixes the problem by allowing the user_options to overwrite the default_options and applying the @hardcoded_options last.

@mtrudel
Copy link
Owner

mtrudel commented Feb 23, 2024

Looks great! I'd always thought that the first value wins, as with keyword lists.

I added some tests to cover this, since it's surprising behaviour.

Thanks for the PR!

@mtrudel mtrudel merged commit 1116dba into mtrudel:main Feb 23, 2024
9 checks passed
@mtrudel
Copy link
Owner

mtrudel commented Feb 23, 2024

Pushed as 1.3.4

@danschultzer
Copy link
Contributor

danschultzer commented Feb 23, 2024

This breaks options for gen_tcp: https://www.erlang.org/doc/man/gen_tcp#listen-2

AFAIK keyword list is an Elixir only thing. In Erlang the options (at least for gen_tcp) is a list of tuples or atoms. I'm setting the ipfamily explicitly so the list will be akin to:[log_level: :warning, :inet6]

@mtrudel
Copy link
Owner

mtrudel commented Feb 23, 2024

Aw shoot you're right. We had fixed that previously but I don't think it's under test, hence the regression

I'm out for the evening but I can fix this up tomorrow. Sorry for the trouble

@mtrudel
Copy link
Owner

mtrudel commented Feb 23, 2024

Fix is up at #112, but there's a failing test for ssl that suggests maybe it's a bit more complicated than gen_tcp. Take a look!

@travelmassive
Copy link

travelmassive commented Feb 24, 2024

I think I'm affected by this issue. Just grabbed the latest bandit (1.2.3) which nudged thousand_island to 1.3.4

My web server was failing with:

2024-02-24T00:18:48.622223+00:00 web.1  |     ** (EXIT) shutdown: failed to start child: {AppWeb.Endpoint, :http}
2024-02-24T00:18:48.622312+00:00 web.1  |         ** (EXIT) shutdown: failed to start child: :listener
2024-02-24T00:18:48.622356+00:00 web.1  |             ** (EXIT) an exception was raised:
2024-02-24T00:18:48.622406+00:00 web.1  |                 ** (ArgumentError) expected a keyword list as the second argument, got: [:inet6]
2024-02-24T00:18:48.622598+00:00 web.1  |                     (thousand_island 1.3.4) lib/thousand_island/transports/tcp.ex:60: ThousandIsland.Transports.TCP.listen/2
2024-02-24T00:18:48.622643+00:00 web.1  |                     (thousand_island 1.3.4) lib/thousand_island/listener.ex:29: ThousandIsland.Listener.init/1
2024-02-24T00:18:48.622689+00:00 web.1  |                     (stdlib 3.17.2) gen_server.erl:423: :gen_server.init_it/2
2024-02-24T00:18:48.622735+00:00 web.1  |                     (stdlib 3.17.2) gen_server.erl:390: :gen_server.init_it/6
2024-02-24T00:18:48.622556+00:00 web.1  |                     (elixir 1.13.4) lib/keyword.ex:922: Keyword.merge/2
 web.1  |                     (stdlib 3.17.2) proc_lib.erl:226: :proc_lib.init_p_do_apply/3

My thousand_island_options config in my prod.exs is:

thousand_island_options: [
      transport_options: [
        :inet6
      ]
    ]

Reverting thousand_island to 1.3.3 fixed it.

Hope this is helpful -- Ian.

@mtrudel
Copy link
Owner

mtrudel commented Feb 24, 2024

Yep. Fix is up in the linked PR. I ran out of time to get it over the line today but should get it out as 1.3.5 tomorrow.

@mtrudel
Copy link
Owner

mtrudel commented Feb 24, 2024

Fix published as 1.3.5!

@travelmassive
Copy link

Thanks, working again :)

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

Successfully merging this pull request may close these issues.

4 participants