5

I've run into a problem where I cannot stop mnesia within my program without causing the app to hang.

I'm presently doing prototyping of mnesia within my erlang app.

In my jaus_app.erl file the start() calls:

{atomic, ok} = mnesia:load_textfile("priv/mnesia_prototype.txt")

My stop() function calls:

mnesia:dump_to_textfile("priv/mnesia_prototype_res.txt"),
mnesia:stop(),

When I comment out these lines and start and stop mnesia from the erlang prompt, I am able to stop my application cleanly.

Should I not use these prototype functions within a fully fledged erlang app?

Ken.

Ken Robinson
  • 153
  • 2
  • 5
  • 5
    This happens because your `stop` function is called from the application controller, which is a `gen_server`, but `mnesia:stop` calls `application:stop(mnesia)` and waits for a response from the application controller - and you have a deadlock. So, the simple answer is "don't use `mnesia:stop` in that callback function"; I don't have a much better suggestion, though :) – legoscia Aug 13 '10 at 15:05

2 Answers2

2

By using systools to create a boot file mnesia is started before my app and stops after my app on shutdown. This fixes the hanging problem which is alluded to by legoscia above. The boot file idea was suggested by Mazen from erlang consulting. Many thanks to him for that suggestion.

Ken Robinson
  • 153
  • 2
  • 5
1

From the erlang docs:

dump_to_textfile(Filename): Dumps all local tables of a mnesia system into a text file which can then be edited (by means of a normal text editor) and then later be reloaded with mnesia:load_textfile/1. Only use this function for educational purposes. Use other functions to deal with real backups.

Matt Williamson
  • 39,165
  • 10
  • 64
  • 72