nickva commented on code in PR #5132:
URL: https://github.com/apache/couchdb/pull/5132#discussion_r1678729278


##########
src/couch/src/couch_bt_engine_header.erl:
##########
@@ -285,6 +286,20 @@ upgrade_epochs(#db_header{} = Header) ->
     DedupedEpochs = remove_dup_epochs(NewEpochs),
     Header#db_header{epochs = DedupedEpochs}.
 
+%% get the node name from the start up configuration as node()
+%% can return nonode@nohost if net_kernel crashes.
+init_node_name() ->
+    init_node_name(init:get_arguments()).
+
+init_node_name([]) ->
+    nonode@nohost;
+init_node_name([{name, [Name]} | _Rest]) ->
+    list_to_existing_atom(Name);
+init_node_name([{sname, [Name]} | _Rest]) ->
+    list_to_existing_atom(Name);
+init_node_name([_ | Rest]) ->
+    init_node_name(Rest).
+

Review Comment:
   There is some danger here if we don't match exactly the node parsing code 
from `init` and `net_kernel` we could get into case where our init_node_name 
doesn't match exactly the output of `node()`.
   
   For instance is someone uses just the name and gets the host automatically 
from the various resolving paths, this will break, it will also break if 
someone uses sname. We don't advise anyone do that, but we did once, and so may 
break people's setup then.
   
   ```
    % erl -noshell -name [email protected] -eval 'io:fwrite("~s~n", [node()]), 
init:stop().'
   [email protected]
    % erl -noshell -name foo -eval 'io:fwrite("~s~n", [node()]), init:stop().'
   [email protected]
   % erl -noshell -sname foo -eval 'io:fwrite("~s~n", [node()]), init:stop().'
   foo@myhostname
   ```
   
   We don't want to be in the business deal `.local` bits and all that given 
that it's kind opaque hidden inside net_kernel machinery.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to