File 3771-inets-fix-httpd-startup-sequence-net_adm-default.patch of Package erlang
From 421479ccd744b0514b229ba1c38eb2b64fcd919d Mon Sep 17 00:00:00 2001
From: Jakub Witczak <kuba@erlang.org>
Date: Mon, 10 Feb 2025 13:33:31 +0100
Subject: [PATCH] inets: fix httpd startup sequence + net_adm default
- when starting httpd, starting httpd_manager first
- default to net_adm:localhost() in httpd_request_handler:init
- avoid calling net_adm for expected execution flows
---
lib/inets/src/http_server/httpd_instance_sup.erl | 12 ++++++------
lib/inets/src/http_server/httpd_request_handler.erl | 13 +++++++++++--
2 files changed, 17 insertions(+), 8 deletions(-)
diff --git a/lib/inets/src/http_server/httpd_instance_sup.erl b/lib/inets/src/http_server/httpd_instance_sup.erl
index d1acbce800..99305cb603 100644
--- a/lib/inets/src/http_server/httpd_instance_sup.erl
+++ b/lib/inets/src/http_server/httpd_instance_sup.erl
@@ -80,22 +80,22 @@ init([ConfigFile, ConfigList, AcceptTimeout, Debug, Address, Port]) ->
Profile = proplists:get_value(profile, ConfigList, ?DEFAULT_PROFILE),
Flags = {one_for_one, 0, 1},
Children = [httpd_connection_sup_spec(Address, Port, Profile),
- httpd_acceptor_sup_spec(Address, Port, Profile, ConfigList, AcceptTimeout,
- undefined),
sup_spec(httpd_misc_sup, Address, Port, Profile),
worker_spec(httpd_manager, Address, Port, Profile,
- ConfigFile, ConfigList,AcceptTimeout)],
+ ConfigFile, ConfigList,AcceptTimeout),
+ httpd_acceptor_sup_spec(Address, Port, Profile, ConfigList, AcceptTimeout,
+ undefined)],
{ok, {Flags, Children}};
init([ConfigFile, ConfigList, AcceptTimeout, Debug, Address, Port, ListenInfo]) ->
httpd_util:enable_debug(Debug),
Profile = proplists:get_value(profile, ConfigList, ?DEFAULT_PROFILE),
Flags = {one_for_one, 0, 1},
Children = [httpd_connection_sup_spec(Address, Port, Profile),
- httpd_acceptor_sup_spec(Address, Port, Profile, ConfigList, AcceptTimeout,
- ListenInfo),
sup_spec(httpd_misc_sup, Address, Port, Profile),
worker_spec(httpd_manager, Address, Port, Profile, ListenInfo,
- ConfigFile, ConfigList, AcceptTimeout)],
+ ConfigFile, ConfigList, AcceptTimeout),
+ httpd_acceptor_sup_spec(Address, Port, Profile, ConfigList, AcceptTimeout,
+ ListenInfo)],
{ok, {Flags, Children}}.
diff --git a/lib/inets/src/http_server/httpd_request_handler.erl b/lib/inets/src/http_server/httpd_request_handler.erl
index f96bf8a531..93f5d1acd5 100644
--- a/lib/inets/src/http_server/httpd_request_handler.erl
+++ b/lib/inets/src/http_server/httpd_request_handler.erl
@@ -99,9 +99,18 @@ init([Manager, ConfigDB, AcceptTimeout]) ->
%% At this point the function httpd_request_handler:start/2 will return.
proc_lib:init_ack({ok, self()}),
{SocketType, Socket} = await_socket_ownership_transfer(AcceptTimeout),
- ServerName = erlang:iolist_to_binary(httpd_util:lookup(ConfigDB, server_name)),
+ ServerName =
+ case httpd_util:lookup(ConfigDB, server_name) of
+ undefined ->
+ %% ERIERL-1190 workaround - on some rare occassions
+ %% server_name can't be read from ets table
+ net_adm:localhost();
+ EtsValue ->
+ EtsValue
+ end,
+ ServerNameBin = erlang:iolist_to_binary(ServerName),
Protocol = protocol(SocketType),
- proc_lib:set_label({Protocol, ServerName}),
+ proc_lib:set_label({Protocol, ServerNameBin}),
Peername = http_transport:peername(SocketType, Socket),
Sockname = http_transport:sockname(SocketType, Socket),
--
2.43.0