Weird dependency: Failed connection to MongoDB instance causes call to ets:lookup/2 to fail with badarg

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Weird dependency: Failed connection to MongoDB instance causes call to ets:lookup/2 to fail with badarg

Whealy, Chris
Hi All

This is more of an FYI...

I have a Cowboy application that does the following during start up:

  1. Start iBrowse
  2. Use iBrowse to make an HTTP request to download a text file containing country information
  3. Parse text file to create a list of countries
  4. Start Cowboy and define routes
  5. Start supervisor passing it the list of countries
  6. Supervisor waits for HTTP requests…

This all works nicely.

I’m now extending the functionality to include a MongoDB. 

At first, I modified the startup sequence to this:

  1. Connect to MongoDB instance and get pid of db server
  2. Start iBrowse
  3. Use iBrowse to make an HTTP request to download a text file containing country information
  4. Parse text file to create a list of countries
  5. Start Cowboy and define routes
  6. Start supervisor passing it the list of countries and MongoDB pid
  7. Supervisor waits for HTTP requests…

If the MongoDB instance is up, then no problem.  However, if the MongoDB instance is down, then step 1 returns the expected {error, econnrefused} when calling mc_worker_api:connect/1 and the db server pid defaults to undefined.  Again, this is all as expected...

But the weird thing is that if the connection to MongoDB fails, then step 3 subsequently fails when iBrowse tries to download the text file.  The specific failure is badarg when calling ets:lookup/2 in line 345 of ibrowse.erl.

This doesn’t make much sense to me at all because the two libraries should be unrelated.

I can make the problem go away by moving the code that connects to MongoDB to be after the iBrowse request, but to me, the weirdness of this error highlights that there might be some underlying problem with the MongoDB library and ets.

Regards

Chris Whealy

SAP Cloud Platform | Strategy & Product Management | Team

SAP UK Ltd, Clockhouse Place, Bedfont Rd, Feltham, Middx, TW14 8HA, England 

M +44 (0)7808 575377
 

Find out more on the Strategy & Product Management Wiki page (SAP internal)
Follow our latest activities in SAP CP User Community Jam Group 

Please consider the impact on the environment before printing this e-mail. 

Twitter: @LogaRhythm
"The voice of ignorance speaks loud and long,
  but the words of the wise are quiet and few"
                                                 Ancient Proverb






_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions