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

Mix Release breaks google_api_compute (file system case sensitivity and elixir 1.16/1.17 issue) #13816

Closed
jfreeze opened this issue Sep 7, 2024 · 9 comments

Comments

@jfreeze
Copy link

jfreeze commented Sep 7, 2024

Elixir and Erlang/OTP versions

Elixir 1.16.2 and 1.17.2
Erlang 27

Operating system

Darwin Kernel Version 23.4.0 and FreeBSD 14.1-RELEASE

Current behavior

Create a new phx project and add the dependency:

 {:google_api_compute, "~> 0.62.0"},

Expected behavior

On MacOS, this app will compile and run with iex -S mix phx.server.

However, running via mix release fails.

mix release.init
mix release
./_build/dev/rel/goog/bin/goog start_iex

fails on MacOS for both Elixir 1.16.2 and 1.17.2 (and master).

❯ ./dev/rel/goog/bin/goog start_iex
(no logger present) unexpected logger message: {log,error,"~s~n",["beam/beam_load.c(180): Error loading module 'Elixir.GoogleApi.Compute.V1.Model.HTTPHealthCheck':\n  module name in object code is 'Elixir.GoogleApi.Compute.V1.Model.HttpHealthCheck'\n"],#{error_logger=>#{emulator=>true,tag=>error},pid=><0.1425.0>,time=>1725717303287378,gl=><0.0.0>}}

(no logger present) unexpected logger message: {log,error,"~s~n",["beam/beam_load.c(180): Error loading module 'Elixir.GoogleApi.Compute.V1.Model.HttpsHealthCheck':\n  module name in object code is 'Elixir.GoogleApi.Compute.V1.Model.HTTPSHealthCheck'\n"],#{error_logger=>#{emulator=>true,tag=>error},pid=><0.1463.0>,time=>1725717303288612,gl=><0.0.0>}}

This appears to be an existing issue for case-insensitive file systems but didn't show up in case-sensitive file systems until Elixir 1.17.

Running the above on FreeBSD 14.1 Release (case sensitive filesystem), the mix release issue does not present for Elixir 1.16.2 but does surface for Elixir 1.17.2 and master.

@jfreeze jfreeze changed the title Mix Release breaks google_api_compute (file system case and elixir 1.16/1.17 issue) Mix Release breaks google_api_compute (file system case sensitivity and elixir 1.16/1.17 issue) Sep 7, 2024
@josevalim
Copy link
Member

This is a bug in the library. It is defining both lowercase and uppercase module names:

https://github.com/googleapis/elixir-google-api/blob/7c5bb004e6b7dfc90832c0b48f3be4acf6f569d1/clients/compute/lib/google_api/compute/v1/model/http_health_check.ex#L18

https://github.com/googleapis/elixir-google-api/blob/7c5bb004e6b7dfc90832c0b48f3be4acf6f569d1/clients/compute/lib/google_api/compute/v1/model/http_health_check_1.ex#L18

Therefore, in a case insensitive file system, both will write to the same .beam file, but only one of them will exist. The library should not define duplicate modules once the casing is removed. :)

@josevalim josevalim closed this as not planned Won't fix, can't repro, duplicate, stale Sep 7, 2024
@jfreeze
Copy link
Author

jfreeze commented Sep 7, 2024

Why does this only show in mix release?

mix compile does not surface the bug, and the app is able to execute the library without issues.

@josevalim
Copy link
Member

mix compile works because the modules are lazily loaded, so unless you try to use both versions of the module, you won't see the issue. In release, modules are preloaded on boot, so it will try to load both, and one of them will fail. You can try setting RELEASE_MODE=interactive ./dev/rel/goog/bin/goog start_iex, so it does not attempt to preload all modules, but it may fail at some point later if you try to load them.

@jfreeze
Copy link
Author

jfreeze commented Sep 7, 2024

I may have missed this, but is defining modules, say Foo and FOO, an error or just not recommended?

Should elixir at least show a warning if such module names are used?

@jfreeze
Copy link
Author

jfreeze commented Sep 7, 2024

I should also point out that this error occurs on 1.17 for case-sensitive file systems. From your original explanation, I would think that it should not be a problem for those filesystems.

@josevalim
Copy link
Member

I may have missed this, but is defining modules, say Foo and FOO, an error or just not recommended?

The Erlang VM is fine with having modules Foo and FOO. The issue is that, when loading these modules from disk, a case insensitive file system will allow only one of them, which when it fails. And that's why it is tricky to detect these errors in case sensitive ones. A module named GoogleApi.Compute.V1.Model.HTTPSHealthCheck has so many different permutations, checking both memory and disk for conflicts could be too expensive.

@jfreeze
Copy link
Author

jfreeze commented Sep 7, 2024

Is there an explanation why this breaks releases for all file systems in 1.17 but worked for case-sensitive file systems in 1.16?

An issue was filed with the library July 2021 googleapis/elixir-google-api#8174 so I don't expect any updates on this to be timely.

I'm rather new to the elixir-google-api lib so not sure why this wasn't addressed years ago or if it is even possible.

I suppose our options at this point are to fork elixir-google-api or write the api's manually.

@josevalim
Copy link
Member

From the issue above, it seems it did happen in earlier Elixir versions. I would also expect it to happen on 1.16, so I will investigate it, but I’d say the 1.17 behavior is the correct one. I also wonder if you can fix this by forking and removing the additional file with duplicate definitions.

@jfreeze
Copy link
Author

jfreeze commented Sep 7, 2024

I've been running in production with 1.16.2 and didn't notice the issue until trying to move to 1.17.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants