elixir-mongodb-driver icon indicating copy to clipboard operation
elixir-mongodb-driver copied to clipboard

Driver and Cloud Run: protocol Enumerable not implemented for

Open NicolasRomeroToledo opened this issue 1 year ago • 5 comments

I'm trying to use Cloud Run as a serverless container to my Phoenix app, in my local environment the connection with local mongo works fine, but in Cloud Run it throw some errors:

24-02-06 17:19:29.485 CLST
20:19:28.388 [notice] Application exited: Test.Application.start(:normal, []) returned an error: shutdown: failed to start child: Mongo
2024-02-06 17:19:29.485 CLST
    ** (EXIT) an exception was raised:
2024-02-06 17:19:29.485 CLST
        ** (Protocol.UndefinedError) protocol Enumerable not implemented for {:error, :servfail} of type Tuple. This protocol is implemented for the following type(s): DBConnection.PrepareStream, DBConnection.Stream, Date.Range, Ecto.Adapters.SQL.Stream, File.Stream, Floki.HTMLTree, Function, GenEvent.Stream, HashDict, HashSet, IO.Stream, Jason.OrderedObject, List, Map, MapSet, Mongo.ChangeStream, Mongo.Stream, Phoenix.LiveView.LiveStream, Postgrex.Stream, Range, Stream, Timex.Interval
2024-02-06 17:19:29.485 CLST
            (elixir 1.16.1) lib/enum.ex:1: Enumerable.impl_for!/1
2024-02-06 17:19:29.485 CLST
            (elixir 1.16.1) lib/enum.ex:166: Enumerable.reduce/3
2024-02-06 17:19:29.485 CLST
            (elixir 1.16.1) lib/enum.ex:4399: Enum.reduce/3
2024-02-06 17:19:29.485 CLST
            (mongodb_driver 1.0.3) lib/mongo/url_parser.ex:185: Mongo.UrlParser.parse_url/1
2024-02-06 17:19:29.485 CLST
            (mongodb_driver 1.0.3) lib/mongo.ex:142: Mongo.start_link/1
2024-02-06 17:19:29.485 CLST
            (stdlib 5.2) supervisor.erl:420: :supervisor.do_start_child_i/3
2024-02-06 17:19:29.485 CLST
            (stdlib 5.2) supervisor.erl:406: :supervisor.do_start_child/2
2024-02-06 17:19:29.485 CLST
            (stdlib 5.2) supervisor.erl:390: anonymous fn/3 in :supervisor.start_children/2

Application.ex file:

    children = [
     ...
      {Mongo,
       [
         name: :mongo,
         url:
           "mongodb+srv://test:[email protected]/test?retryWrites=true&w=majority",
         pool_size: 3
       ]}
    ...
    ]

Did anyone of you have similar problems and/or ideas how to fix it?

Cheers

Nick

NicolasRomeroToledo avatar Feb 06 '24 20:02 NicolasRomeroToledo

Please try to upgrade the driver to the latest version. You are using an old one.

zookzook avatar Feb 07 '24 06:02 zookzook

Thanks @zookzook, I just updated it and it keeps throwing same error.


   ** (EXIT) an exception was raised:


2024-02-07 12:08:27.144 CLST
        ** (Protocol.UndefinedError) protocol Enumerable not implemented for {:error, :servfail} of type Tuple. This protocol is implemented for the following type(s): DBConnection.PrepareStream, DBConnection.Stream, Date.Range, Ecto.Adapters.SQL.Stream, File.Stream, Function, GenEvent.Stream, HashDict, HashSet, IO.Stream, Jason.OrderedObject, List, Map, MapSet, Mongo.ChangeStream, Mongo.Stream, Phoenix.LiveView.LiveStream, Postgrex.Stream, Range, Stream, Timex.Interval


2024-02-07 12:08:27.144 CLST
            (elixir 1.16.1) lib/enum.ex:1: Enumerable.impl_for!/1


2024-02-07 12:08:27.144 CLST
            (elixir 1.16.1) lib/enum.ex:166: Enumerable.reduce/3


2024-02-07 12:08:27.144 CLST
            (elixir 1.16.1) lib/enum.ex:4399: Enum.reduce/3


2024-02-07 12:08:27.144 CLST
            (mongodb_driver 1.2.1) lib/mongo/url_parser.ex:189: Mongo.UrlParser.parse_url/1


2024-02-07 12:08:27.144 CLST
            (mongodb_driver 1.2.1) lib/mongo.ex:140: Mongo.start_link/1


2024-02-07 12:08:27.144 CLST
            (stdlib 5.2) supervisor.erl:420: :supervisor.do_start_child_i/3


2024-02-07 12:08:27.144 CLST
            (stdlib 5.2) supervisor.erl:406: :supervisor.do_start_child/2


2024-02-07 12:08:27.145 CLST
            (stdlib 5.2) supervisor.erl:390: anonymous fn/3 in :supervisor.start_children/2

NicolasRomeroToledo avatar Feb 07 '24 15:02 NicolasRomeroToledo

I believe, the error is returned by the erlang DNS stuff:


res_error() =
    formerr | qfmterror | servfail | nxdomain | notimp | refused |
    badvers | timeout
    

It seems the server is not able to resolve domain names.

zookzook avatar Feb 07 '24 15:02 zookzook

Local environment returns some errors about NXDOMAIN when verify_peer is activated, so I just turned it off. I think it could be a problem with Erlang (or the O.S used to compile and run it), I think Cloud Run (the server) is not the problem, I mean, i've others projects using NodeJs connected to Mongo Atlas using Cloud Run also and none of them returns errors about that.

NicolasRomeroToledo avatar Feb 07 '24 15:02 NicolasRomeroToledo

In the case of ssl you need to extend the configuration. Erlang does not use the local ca certs of the OS. Check the readme regarding the SSL configuration.

zookzook avatar Feb 07 '24 15:02 zookzook