Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Can't start etorrent without dht_state.dets table #9

Closed
hummermania opened this Issue · 6 comments

2 participants

@hummermania

I try to start etorrent then follow your instructions. But after sometime it is crashes. I lookup the log messages and read what etorrent_sup fails when try starting etorrent_dht_state - can't find the ../spool/dht_state.dets file. I tried to create some empty file -but its dont work. This file must contain the NodeId and ListNodes tuples. If you have the default this file - get me please or add the check when file and path "spool" doesn't exists.

@jlouis
Owner

What are you trying to do?
What are you observing?
What do you expect to happen instead?

@hummermania

I want to run all etorrent project on the linux.

$ mkdir ~/etorrent
$ cd etorrent
$ git clone https://github.com/jlouis/etorrent_core.git
.. copy the rebar into the folder
$ make get-deps  (so it's work if I correct the Makefile rebar -> ./rebar and use "get-deps")
$ make compile
$ make rel
... edit the config file to set the path for the dht_state fast_resume tables and others
$ ./rel/etorrent/bin/etorrent console

After deploy all sources, compile etorrent, etorrent_core and dependencies I can run the etorrent. But after 15-25 sec. it crashes with errors. I analyze the debug/log messages and find the line where gen_server etorrent_dht_state fails to run because not found dh_state table in the spool folder (it also can not exists, I create it manually).
I see the code of etorrent_dht_state.erl and found that in the func 'load_state' it cannot check that file is not found.

Look at this:

load_state(Filename) ->
    ErrorFmt = "Failed to load state from ~s (~w)",
    case file:read_file(Filename) of
        {ok, BinState} ->
            case (catch load_state_(BinState)) of
                {'EXIT', Reason}  ->
                    ErrorArgs = [Filename, Reason],
                    error_logger:error_msg(ErrorFmt, ErrorArgs),
                    {etorrent_dht:random_id(), []};
                {_, _}=State ->
                    error_logger:info_msg("Loaded state from ~s", [Filename]),
                    State
            end;
        {error, Reason} ->
            ErrorArgs = [Filename, Reason],
            error_logger:error_msg(ErrorFmt, ErrorArgs),
            {etorrent_dht:random_id(), []}
    end.

The first case try to open file ./spool/dht_state.erl and if they can not be found we follow to {error, Reason} and have message in the log about error. When I create the empty file I see that 'catch load_state_(BinState)' throw error because in the load_state_ erlang not found clause for call binary_to_term(<<>>). BinState - empty binary that reading from empty dht_state table.

load_state_(BinState) ->
    PersistentState = binary_to_term(BinState),
    ....

I understand that I must have the dht_state table in the correct format: '[{node_id, Self}, {node_set, NodeList}]'.
But I don't know that to create this file. And I can't run the etorrent to understanding and learning!

P.S. Sorry of my English

@jlouis
Owner

This sounds like a bug. I'll investigate it when I have time to do so.

@jlouis
Owner

Yes, this is a bug, but a subtle one. The etorrent_dht_state gen_server has a call, etorrent_dht_state:dump_state() which you can try using. This should output the state to disk and is the normal way to generate this file. Upon termination of the gen_server, this state is dumped. And herein lies the trouble!

When a gen_server is terminated by its supervisor, it gets an exit(Pid, shutdown) sent to it. But since the process is not trapping exits, this means that the process is brutally killed and we never get to dump the current state. In this case, where there is an important thing to do, we should capture it and then write the state to disk nicely by trapping exits in the gen_server and then have it handle the cases normal and shutdown the way we expect it to handle it.

@jlouis jlouis was assigned
@jlouis
Owner

gh-9 is an attempt at a fix, but it has not seen lots of testing yet, so it may very well be wrong right now.

@hummermania

Well, thanks! It's work. I start, wait while it crashes, make the dht_state file, and start again. I think that create the dht_state file need in the first run, when they not exists.
So I try to run webui today =)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.