couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vatam...@apache.org
Subject [couchdb] 01/01: Do not crash couch_log application when gen_* servers send extra args
Date Wed, 17 Oct 2018 20:32:50 GMT
This is an automated email from the ASF dual-hosted git repository.

vatamane pushed a commit to branch fix-log-to-handle-extra-args
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit ff9b6d1d021d8857edfd57327f4a6f7746f23ff7
Author: Nick Vatamaniuc <vatamane@apache.org>
AuthorDate: Wed Oct 17 16:24:28 2018 -0400

    Do not crash couch_log application when gen_* servers send extra args
    
    gen_server, gen_fsm and gen_statem might send extra args when terminating. This
    is a recent behavior, and not handling these extra args could lead to couch_log
    application crashing and taking down the whole VM with it.
---
 src/couch_log/src/couch_log_formatter.erl       | 12 ++++++------
 src/couch_log/test/couch_log_formatter_test.erl | 10 ++++++----
 2 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/src/couch_log/src/couch_log_formatter.erl b/src/couch_log/src/couch_log_formatter.erl
index 5be3619..3464800 100644
--- a/src/couch_log/src/couch_log_formatter.erl
+++ b/src/couch_log/src/couch_log_formatter.erl
@@ -58,18 +58,18 @@ format(Level, Pid, Msg) ->
 
 format({error, _GL, {Pid, "** Generic server " ++ _, Args}}) ->
     %% gen_server terminate
-    [Name, LastMsg, State, Reason] = Args,
+    [Name, LastMsg, State, Reason | Extra] = Args,
     MsgFmt = "gen_server ~w terminated with reason: ~s~n" ++
-                "  last msg: ~p~n     state: ~p",
-    MsgArgs = [Name, format_reason(Reason), LastMsg, State],
+                "  last msg: ~p~n     state: ~p~n    extra: ~p",
+    MsgArgs = [Name, format_reason(Reason), LastMsg, State, Extra],
     format(error, Pid, MsgFmt, MsgArgs);
 
 format({error, _GL, {Pid, "** State machine " ++ _, Args}}) ->
     %% gen_fsm terminate
-    [Name, LastMsg, StateName, State, Reason] = Args,
+    [Name, LastMsg, StateName, State, Reason | Extra] = Args,
     MsgFmt = "gen_fsm ~w in state ~w terminated with reason: ~s~n" ++
-                " last msg: ~p~n     state: ~p",
-    MsgArgs = [Name, StateName, format_reason(Reason), LastMsg, State],
+                " last msg: ~p~n     state: ~p~n    extra: ~p",
+    MsgArgs = [Name, StateName, format_reason(Reason), LastMsg, State, Extra],
     format(error, Pid, MsgFmt, MsgArgs);
 
 format({error, _GL, {Pid, "** gen_event handler" ++ _, Args}}) ->
diff --git a/src/couch_log/test/couch_log_formatter_test.erl b/src/couch_log/test/couch_log_formatter_test.erl
index a8f69b2..b660336 100644
--- a/src/couch_log/test/couch_log_formatter_test.erl
+++ b/src/couch_log/test/couch_log_formatter_test.erl
@@ -45,7 +45,7 @@ gen_server_error_test() ->
         {
             Pid,
             "** Generic server and some stuff",
-            [a_gen_server, {foo, bar}, server_state, some_reason]
+            [a_gen_server, {foo, bar}, server_state, some_reason, sad, args]
         }
     },
     ?assertMatch(
@@ -59,7 +59,8 @@ gen_server_error_test() ->
         "gen_server a_gen_server terminated",
         "with reason: some_reason",
         "last msg: {foo,bar}",
-        "state: server_state"
+        "state: server_state",
+        "extra: \\[sad,args\\]"
     ]).
 
 
@@ -71,7 +72,7 @@ gen_fsm_error_test() ->
         {
             Pid,
             "** State machine did a thing",
-            [a_gen_fsm, {ohai,there}, state_name, curr_state, barf]
+            [a_gen_fsm, {ohai,there}, state_name, curr_state, barf, sad, args]
         }
     },
     ?assertMatch(
@@ -85,7 +86,8 @@ gen_fsm_error_test() ->
         "gen_fsm a_gen_fsm in state state_name",
         "with reason: barf",
         "last msg: {ohai,there}",
-        "state: curr_state"
+        "state: curr_state",
+        "extra: \\[sad,args\\]"
     ]).
 
 


Mime
View raw message