fireproofsocks

fireproofsocks

Mongo connection times out, but only when it is used by a dependency

I’m experiencing some odd behavior. I’m using mongodb_driver (v0.9.0) in an app (app1), and it’s been working great. But suddenly, when I use that app as a dependency (by app2), suddenly all my mongo queries time out.

My guess is that I’m stepping into something tricky with supervisors or something. (Why am I doing this? My thought was that app1 defines all the schemas and contexts for how to access resources, and I didn’t want to duplicate any of that in app2 – I want app2 to be ignorant about the “implementation details”).

app1 wraps the Mongo start like this:

def MyMongoWrapper do
  def start_link(opts \\ []) do
    # Read some config here... user, password, etc.
    Mongo.start_link(opts)
  end
end

which is ref’d in app1’s application.ex:

def start(_type, _args) do
    children = [
      {MyMongoWrapper, []}
    ]
    opts = [strategy: :one_for_one, name: App1.Supervisor]
    Supervisor.start_link(children, opts)
  end

So all is well with the world in app1: I can start it up and make queries as expected.

But when I start working with app2 and I use app1 as a dependency, nothing seems to work, even though app1 DOES get started and the mongo process DOES get started.

Instead of relying on “implicit starting” (?) that happens when an app lists another app as a dependency, I tried manually listing App1 in app2’s supervision tree, but calls to Mongo still time out.

Likewise, if I remove all the children from app1’s application.ex and list the MyMongoWrapper in app2’s application.ex, I get the same result: any Mongo queries cause an exit due to timeout.

It’s really making me scratch my head and wonder why things are working in app1 at all. The config and everything seems to be exactly the same.

Does anyone have any ideas of what might be causing this type of behavior or other things I could check?

Marked As Solved

zookzook

zookzook

The driver 0.9.2 does not support 4.0. Sorry, you need to downgrade the driver. It does not support AWS DocumentDB.

Also Liked

zookzook

zookzook

I assume, your configuration is not working. Please turn on logging: GitHub - zookzook/elixir-mongodb-driver: MongoDB driver for Elixir · GitHub, then you see more information about.

fireproofsocks

fireproofsocks

Thanks for the prompt reply @zookzook! This is interesting. I have verified that BOTH app1 and app2 have the IDENTICAL configuration options, something like this:

[
  name: :my_mongo,
  pool_size: 20,
  url: "mongodb://:@localhost:/app1_dev",
  timeout: 15000,
  ssl: false
]

Note that the URL looks funny in dev because we don’t specify a user, password, port, or parameters (which do get set when connecting to a production mongo instance).

What is really curious is that BOTH app1 AND app2 show errors on startup when I set the config to include log: true:

10:13:33.630 [error] an exception was raised logging %DBConnection.LogEntry{call: :execute, connection_time: 5298000, decode_time: 6000, idle_time: 548338000, params: [], pool_time: 147000, query: %Mongo.Query{action: {:exec_hello, []}}, result: {:ok, %Mongo.Query{action: {:exec_hello, []}}, {%{"code" => 59, "codeName" => "CommandNotFound", "errmsg" => "no such command: 'helloOk'", "ok" => 0.0}, %Mongo.Events.CommandStartedEvent{command: :hello, command_name: :hello, connection_id: #PID<0.815.0>, database_name: "admin", operation_id: nil, request_id: 1}, 0, 5240}}}: ** (BadFunctionError) expected a function, got: true
    (db_connection 2.4.2) lib/db_connection.ex:1532: DBConnection.log/2
    (db_connection 2.4.2) lib/db_connection.ex:1510: DBConnection.log/5
    (mongodb_driver 0.9.2) lib/mongo.ex:1526: Mongo.exec_hello/2
    (stdlib 3.16.1) timer.erl:166: :timer.tc/1
    (mongodb_driver 0.9.2) lib/mongo/monitor.ex:239: Mongo.Monitor.get_server_description/1
    (mongodb_driver 0.9.2) lib/mongo/monitor.ex:164: Mongo.Monitor.update_server_description/1
    (mongodb_driver 0.9.2) lib/mongo/monitor.ex:151: Mongo.Monitor.handle_info/2
    (stdlib 3.16.1) gen_server.erl:695: :gen_server.try_dispatch/4
    (stdlib 3.16.1) gen_server.erl:771: :gen_server.handle_msg/6
    (stdlib 3.16.1) proc_lib.erl:226: :proc_lib.init_p_do_apply/3

app1 throws 3 of these errors, and then they pop up intermittently, but app1 can go on to successfully issue commands, e.g.

# app1
iex> Mongo.insert_one(:my_mongo, "foo", %{what: "up"})
{:ok,
 %Mongo.InsertOneResult{
   acknowledged: true,
   inserted_id: #BSON.ObjectId<633d93aac6e47b35cb0d1fc5>
 }}

whereas app2 just throws an unending stream of these errors into the log. The same command on app2 yields a timeout:

# app2
iex> Mongo.insert_one(:my_mongo, "foo", %{what: "up"})
** (exit) exited in: GenServer.call(:my_mongo, {:checkout_session, :write, [write_counter: 1]}, 60000)
    ** (EXIT) time out
    (elixir 1.13.4) lib/gen_server.ex:1030: GenServer.call/3
    (mongodb_driver 0.9.2) lib/mongo/session.ex:142: Mongo.Session.start_session/3
    (mongodb_driver 0.9.2) lib/mongo/session.ex:694: Mongo.Session.in_session/5
    (mongodb_driver 0.9.2) lib/mongo.ex:1482: Mongo.issue_command/4
    (mongodb_driver 0.9.2) lib/mongo.ex:849: Mongo.insert_one/4

It’s like Mongo “knows” how its server is getting started or something. Very curious. Any other ideas for what could explain this behavior?

I just noticed app1 shows "mongodb_driver": {:hex, :mongodb_driver, "0.9.1" in its mix.lock whereas app2 specifies "mongodb_driver": {:hex, :mongodb_driver, "0.9.2" … so I’m gonna suss that out

zookzook

zookzook

If both apps have identical configurations then they started the supervisor related stuff twice. Use only one configuration. A topology should only started as a singleton.

Where Next?

Popular in Questions Top

New
tduccuong
Hi, is there any work on GUI with Elixir, that is similar to Electron/Javascript? My idea is to bundle Phoenix and BEAM into a single se...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New

Other popular topics Top

malloryerik
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode. The solution seems to be, in a hyphena...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID&lt;0.412.0&gt; terminating ** (Postgrex.Error) FATAL...
New
aesmail
Hello guys, I have finally made it. I created an admin interface for a framework. It’s been on my todo list for years and with the curre...
New
nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement