noss / iserve Goto Github PK
View Code? Open in Web Editor NEWA small http server for erlang.
Home Page: http://frihjul.net/iserve
License: BSD 3-Clause "New" or "Revised" License
A small http server for erlang.
Home Page: http://frihjul.net/iserve
License: BSD 3-Clause "New" or "Revised" License
I ran into this issue when I had a gen_server module that called iserve:add_server/4 during init. If the module died, it was restarted by the supervisor, then during the call to iserve_master:call_add_server/2, iserve_server_sup:add_server/2 would return {error, {already_started, Pid}}
rather than {ok, Pid}
, which caused a badmatch in the iserve_master process, killing it.
The following patch fixes the issue:
---
src/iserve_master.erl | 3 +--
1 files changed, 1 insertions(+), 2 deletions(-)
diff --git a/src/iserve_master.erl b/src/iserve_master.erl
index 02872fc..879c6e9 100644
--- a/src/iserve_master.erl
+++ b/src/iserve_master.erl
@@ -51,9 +51,8 @@ code_change(_OldVsn, State, _Extra) ->
%%% Internal functions
call_add_server({_Starter, _Port, _Callback, _Context}=Conf, S) ->
- {ok, Pid} = iserve_server_sup:add_server(S#state.supervisor, Conf),
+ Reply = iserve_server_sup:add_server(S#state.supervisor, Conf),
%% TODO: Monitor the little bugger
- Reply = {ok, Pid},
{reply, Reply, S}.
call_del_server(Pid, S) ->
--
1.6.3.3
Hi,
There is a bug in iserve/src/iserve_server.erl, this bug is also present in http://www.trapexit.org/A_fast_web_server_demonstrating_some_undocumented_Erlang_features article, it happens when the acceptor process (iserve_socket) receives two consecutives abnormal exists (easy to simulate in shell), upon the second exit, the function "handle_info({'EXIT', Pid, _Abnormal}, #state{acceptor=Pid} = State)" won't match and a new acceptor will not be created, silently stopping the service, the following patch solves the problem:
@@ -91,12 +91,12 @@ handle_info({'EXIT', Pid, normal}, #state{acceptor=Pid} = State) ->
%% The current acceptor has died, wait a little and try again
handle_info({'EXIT', Pid, _Abnormal}, #state{acceptor=Pid} = State) ->
timer:sleep(2000),
- iserve_socket:start_link(State#state.cb_mod,
+ New_pid = iserve_socket:start_link(State#state.cb_mod,
State#state.cb_data,
self(),
State#state.listen_socket,
State#state.port),
- {noreply, State};
+ {noreply, State#state{acceptor=New_pid}};
handle_info(_Info, State) ->
{noreply, State}.
Alexandre Girao
https://github.com/alexgirao
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.