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

Replace tuple style supervisor child_spec with map on cowboy adapter #266

Merged
merged 4 commits into from Oct 12, 2022

Conversation

prihandi
Copy link
Contributor

PR for #265 @polvalente

  • Changing child_spec format/type from Supervisor.Spec.spec() (a tuple) to Supervisor.child_spec() (a map)
  • Updating test case

Copy link
Contributor

@polvalente polvalente left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@prihandi
Copy link
Contributor Author

I see CI pipeline failed on dialyzer check because current :ranch.child_spec will never return a map,

Should I suppress dialyzer warning for this?

@polvalente
Copy link
Contributor

I see CI pipeline failed on dialyzer check because current :ranch.child_spec will never return a map,

Should I suppress dialyzer warning for this?

Does the code allow for returning a map, though?

@prihandi
Copy link
Contributor Author

Yes, for newer version of :ranch

@polvalente
Copy link
Contributor

Looks like this PR should also update Ranch

@@ -42,13 +42,26 @@ defmodule GRPC.Server.Adapters.Cowboy do
{:ranch_tcp, :cowboy_clear}
end

{ref, mfa, type, timeout, kind, modules} =
:ranch.child_spec(ref, transport, trans_opts, protocol, proto_opts)
case :ranch.child_spec(ref, transport, trans_opts, protocol, proto_opts) do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we update ranch, we won't need this case

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we update :ranch, then the tuple version would never match afterward, the dialyzer would see it as warning

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, because we won't need to support the tuple version :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can't update ranch because cowlib still dependent on version 1.8.0 :(

mix.exs Outdated
@@ -44,6 +44,7 @@ defmodule GRPC.Mixfile do
# but we can't depend on an RC for releases
{:gun, "~> 2.0.1", hex: :grpc_gun},
{:cowlib, "~> 2.11"},
{:ranch, "~> 2.0", override: true},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need the override?
We can't publish the package with the override here :(

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because cowlib still reference to "1.8.0", this means this approach need to suppress warning from dialyzer on no_match for :ranch.child_spec

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll revert it back

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, so we can't update ranch after all.
Best approach is to revert to the case implementation and ignore the dialyzer warning for that specific line.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hex blocks packages that have override: true for any dependencies, because override should only be used at the top level

@@ -42,13 +44,24 @@ defmodule GRPC.Server.Adapters.Cowboy do
{:ranch_tcp, :cowboy_clear}
end

{ref, mfa, type, timeout, kind, modules} =
:ranch.child_spec(ref, transport, trans_opts, protocol, proto_opts)
case :ranch.child_spec(ref, transport, trans_opts, protocol, proto_opts) do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a comment here and on the dialyzer warning explaining why these pieces of code are here?

Copy link
Contributor Author

@prihandi prihandi Aug 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's just a no_match/never match warning since :ranch version 1.8.0 will always return a tuple lilke current implementation, while new version (2.x.x) will always return map.
So, even though we update ranch the warning still exist because it'll just return one type of child_spec, a tuper or a map
And turned out we can't update :ranch because :cowlib still dependent on version 1.8.0

I think I'll close my PR, since it'd not be generic use cases for having support for both of supervisor child_spec
I'll use my forked version for my plugin

Thanks Paulo

@polvalente polvalente merged commit f21e2e1 into elixir-grpc:master Oct 12, 2022
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.

None yet

2 participants