fireproofsocks
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?
Trending in Questions
Other Trending Topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ai
- #ecto-query
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #elixirconf-eu
- #api
- #forms
- #metaprogramming
- #hex










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
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
Thanks for the prompt reply @zookzook! This is interesting. I have verified that BOTH
app1andapp2have the IDENTICAL configuration options, something like this: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
app1ANDapp2show errors on startup when I set the config to includelog: true:app1throws 3 of these errors, and then they pop up intermittently, butapp1can go on to successfully issue commands, e.g.whereas
app2just throws an unending stream of these errors into the log. The same command onapp2yields a timeout: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
app1shows"mongodb_driver": {:hex, :mongodb_driver, "0.9.1"in itsmix.lockwhereasapp2specifies"mongodb_driver": {:hex, :mongodb_driver, "0.9.2"… so I’m gonna suss that outzookzook
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.
fireproofsocks
To clarify: the supervisor is only started once, I’m just comparing behaviors between the 2 apps. When
app1is run as a stand-alone app, it starts up the supervisor andMongo. Whenapp2starts, it doesn’t explicitly start anything, it defers toapp1to start up its stuff. (I only explored variants to see if I could figure out what was going on here).fireproofsocks
Aha, the problem seems to be with version 0.9.2. As soon as I force
app2to use0.9.1, it behaves the same way asapp1: the log periodically shows the error (see above), but it is able to issue commands.So really this has nothing to do with supervisors, it’s just something to do with differences between v0.9.1 and v0.9.2. The fact that errors are being logged may indicate something problematic, however.
I should add that I’m connecting to an instance of mongo v4.0.0 – this is because in production we rely on AWS DocumentDB, and v4.0.0 seems to be the most similar.
zookzook
The driver 0.9.2 does not support 4.0. Sorry, you need to downgrade the driver. It does not support AWS DocumentDB.
fireproofsocks
Ok, we’ll pin it to v0.9.1. Thanks for the responses! They are much appreciated.
This really is a great driver – I’d love to see an Ecto adapter for it. We’ve got a handful of code that could maybe be adapted for that.
Interesting re DocumentDB: we are using DocumentDB in production with
mongodb_driverv0.9.1 and it has been working fine – admittedly our queries are limited to mostly CRUD without a lot of filters or sorting, but it hasn’t had any issues.zookzook
The handshake workflow changed. Instead of using ismaster, the new handshake workflow uses hello!
The hello command was introduced with Mongo 4.2 or 4.4, so I decided to use the new hello command.
zookzook
I think, you found a bug in the hello command. I will fix it and then the driver should work with AWS DocumentDB!
fireproofsocks
That’s great! Do you want me to file a bug with steps to reproduce?