You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by wo...@apache.org on 2020/10/09 16:40:00 UTC

[couchdb-ibrowse] branch upstream-merge created (now 1815716)

This is an automated email from the ASF dual-hosted git repository.

wohali pushed a change to branch upstream-merge
in repository https://gitbox.apache.org/repos/asf/couchdb-ibrowse.git.


      at 1815716  Strip sensitive data from state

This branch includes the following new commits:

     new 4e1cffa  Get a new lb pid if existing pid is not alive
     new 1815716  Strip sensitive data from state

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[couchdb-ibrowse] 02/02: Strip sensitive data from state

Posted by wo...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

wohali pushed a commit to branch upstream-merge
in repository https://gitbox.apache.org/repos/asf/couchdb-ibrowse.git

commit 18157162f0fc79f51d0b9542892e25fb76127de2
Author: ILYA Khlopotov <ii...@apache.org>
AuthorDate: Thu Jul 23 08:15:02 2020 -0700

    Strip sensitive data from state
---
 src/ibrowse_http_client.erl | 42 +++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 41 insertions(+), 1 deletion(-)

diff --git a/src/ibrowse_http_client.erl b/src/ibrowse_http_client.erl
index e59228c..df8eb93 100644
--- a/src/ibrowse_http_client.erl
+++ b/src/ibrowse_http_client.erl
@@ -33,7 +33,8 @@
          handle_cast/2,
          handle_info/2,
          terminate/2,
-         code_change/3
+         code_change/3,
+         format_status/2
         ]).
 
 -include("ibrowse.hrl").
@@ -321,10 +322,49 @@ terminate(_Reason, #state{lb_ets_tid = Tid} = State) ->
 code_change(_OldVsn, State, _Extra) ->
     {ok, State}.
 
+
+%%--------------------------------------------------------------------
+%% Function: format_status/2
+%% Purpose: Clean process state before logging
+%% Returns: key value list
+%%--------------------------------------------------------------------
+format_status(_Opt, [_PDict, State]) ->
+    #state{
+        reqs=Reqs,
+        reply_buffer=ReplyBuf,
+        recvd_headers=RCVDHeaders,
+        raw_headers=RawHeaders,
+        chunk_size_buffer=ChunkSizeBuf,
+        cur_req=Request
+    } = State,
+    ScrubbedReq = Request#request{url=url_strip_password(Request#request.url)},
+    Scrubbed = State#state{
+        socks5_user=nil,
+        socks5_password=nil,
+        reqs={queue_length, queue:len(Reqs)},
+        reply_buffer={byte_size, byte_size(ReplyBuf)},
+        recvd_headers=lists:map(fun({K, _V}) -> K end, RCVDHeaders),
+        raw_headers={byte_size, byte_size(RawHeaders)},
+        chunk_size_buffer={byte_size, byte_size(ChunkSizeBuf)},
+        cur_req=ScrubbedReq
+    },
+    [{data, [{"State",
+        lists:zip(
+            record_info(fields, state),
+            tl(tuple_to_list(Scrubbed))
+        )
+    }]}].
+
 %%--------------------------------------------------------------------
 %%% Internal functions
 %%--------------------------------------------------------------------
 
+url_strip_password(Url) ->
+    re:replace(Url,
+        "(http|https|socks5)://([^:]+):[^@]+@(.*)$",
+        "\\1://\\2:*****@\\3",
+        [{return, list}]).
+
 %%--------------------------------------------------------------------
 %% Handles data recvd on the socket
 %%--------------------------------------------------------------------


[couchdb-ibrowse] 01/02: Get a new lb pid if existing pid is not alive

Posted by wo...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

wohali pushed a commit to branch upstream-merge
in repository https://gitbox.apache.org/repos/asf/couchdb-ibrowse.git

commit 4e1cffa6c34bde7fdbc90ed4dd9729090a199c36
Author: Joan Touzet <jo...@atypical.net>
AuthorDate: Fri Oct 9 12:38:25 2020 -0400

    Get a new lb pid if existing pid is not alive
    
    Re-port of #2 to upstream
---
 src/ibrowse.erl       | 22 ++++++++++++++++------
 test/ibrowse_test.erl | 19 +++++++++++++++++++
 2 files changed, 35 insertions(+), 6 deletions(-)

diff --git a/src/ibrowse.erl b/src/ibrowse.erl
index 2066799..f945b93 100644
--- a/src/ibrowse.erl
+++ b/src/ibrowse.erl
@@ -342,12 +342,7 @@ send_req(Url, Headers, Method, Body, Options, Timeout) ->
         #url{host = Host,
              port = Port,
              protocol = Protocol} = Parsed_url ->
-            Lb_pid = case ets:lookup(ibrowse_lb, {Host, Port}) of
-                         [] ->
-                             get_lb_pid(Parsed_url);
-                         [#lb_pid{pid = Lb_pid_1}] ->
-                             Lb_pid_1
-                     end,
+            Lb_pid = lb_pid(Host, Port, Parsed_url),
             Max_sessions = get_max_sessions(Host, Port, Options),
             Max_pipeline_size = get_max_pipeline_size(Host, Port, Options),
             Max_attempts = get_max_attempts(Host, Port, Options),
@@ -367,6 +362,21 @@ send_req(Url, Headers, Method, Body, Options, Timeout) ->
             {error, {url_parsing_failed, Err}}
     end.
 
+
+lb_pid(Host, Port, Url) ->
+    case ets:lookup(ibrowse_lb, {Host, Port}) of
+        [] ->
+            get_lb_pid(Url);
+        [#lb_pid{pid = Pid}] ->
+            case is_process_alive(Pid) of
+                true ->
+                    Pid;
+                false ->
+                    ets:delete(ibrowse_lb, {Host, Port}),
+                    get_lb_pid(Url)
+            end
+    end.
+
 try_routing_request(Lb_pid, Parsed_url,
                     Max_sessions, 
                     Max_pipeline_size,
diff --git a/test/ibrowse_test.erl b/test/ibrowse_test.erl
index cd78049..dd156da 100644
--- a/test/ibrowse_test.erl
+++ b/test/ibrowse_test.erl
@@ -27,6 +27,7 @@
          test_head_transfer_encoding/1,
          test_head_response_with_body/0,
          test_head_response_with_body/1,
+         test_dead_lb_pid/0,
          test_303_response_with_no_body/0,
          test_303_response_with_no_body/1,
          test_303_response_with_a_body/0,
@@ -58,6 +59,7 @@
                       {local_test_fun, test_pipeline_head_timeout, []},
                       {local_test_fun, test_head_transfer_encoding, []},
                       {local_test_fun, test_head_response_with_body, []},
+                      {local_test_fun, test_dead_lb_pid, []},
                       {local_test_fun, test_303_response_with_a_body, []},
 		      {local_test_fun, test_303_response_with_no_body, []},
                       {local_test_fun, test_binary_headers, []},
@@ -840,6 +842,23 @@ do_test_20122010_1(Expected_resp, Req_id, Acc) ->
     end.
 
 %%------------------------------------------------------------------------------
+%% Test that when an lb process dies, its entry is removed from the ibrowse_lb
+%% table by the next requestor and replaced with a new process
+%%------------------------------------------------------------------------------
+test_dead_lb_pid() ->
+    {Host, Port} = {"localhost", 8181},
+    Url = "http://" ++ Host ++ ":" ++ integer_to_list(Port),
+    {ok, "200", _, _} = ibrowse:send_req(Url, [], get),
+    [{lb_pid, {Host, Port}, Pid}] = ets:lookup(ibrowse_lb, {Host, Port}),
+    true = exit(Pid, kill),
+    false = is_process_alive(Pid),
+    {ok, "200", _, _} = ibrowse:send_req(Url, [], get),
+    [{lb_pid, {Host, Port}, NewPid}] = ets:lookup(ibrowse_lb, {Host, Port}),
+    true = NewPid /= Pid,
+    true = is_process_alive(NewPid),
+    success.
+
+%%------------------------------------------------------------------------------
 %% Test requests where body is generated using a Fun
 %%------------------------------------------------------------------------------
 test_generate_body_0() ->