anchor.diff:                            {next_state, pstate(), #state{}}.
   do_reconnect(State = #state{sock = undefined,
                               reconnect_tref = undefined,
  +                            buf=Buf,
                               failures = Failures}) ->
       case connect(State) of
           {ok, Sock} ->
               ?INFO("drain_id=~p channel_id=~p dest=~s "
                     "state=disconnected at=connect try=~p sock=~p",
                     log_info(State, [Failures + 1, Sock])),
  +            NewBuf = case logplex_msg_buffer:len(Buf) =:= ?SHRINK_BUF_SIZE of
  +                        true -> logplex_msg_buffer:resize(?DEFAULT_BUF_SIZE, Buf);
  +                        false -> Buf
  +                    end,
               NewState = State#state{sock=Sock,
                                      reconnect_tref = undefined,
                                      send_tref = undefined,
  +                                   buf = NewBuf,
                                      connect_time=os:timestamp()},
               send(NewState);
           {error, Reason} ->
  
positive.code:                 port :: inet:port_number(),
                  sock = undefined :: 'undefined' | inet:socket(),
                  %% Buffer for messages while disconnected
                  buf = logplex_msg_buffer:new() :: logplex_msg_buffer:buf(),
                  %% Last time we connected or successfully sent data
                  last_good_time :: 'undefined' | erlang:timestamp(),
                  %% TCP failures since last_good_time
  
negative.code:         _EnoughTime ->
              do_reconnect(State)
      end;
  reconnect(State = #state{failures = F, last_good_time=LastGood, buf=Buf}) ->
      Max = logplex_app:config(tcp_syslog_backoff_max, 300),
      BackOff = case length(integer_to_list(Max, 2)) of
                    MaxExp when F > MaxExp -> Max;
                    _ -> 1 bsl F
                end,
      NewBuf = case logplex_msg_buffer:len(Buf) =:= ?SHRINK_BUF_SIZE of
          true -> Buf;
          false when is_tuple(LastGood), tuple_size(LastGood) =:= 3 ->
              case now_to_msec(LastGood) < now_to_msec(os:timestamp())-?SHRINK_TIMEOUT of
                  true -> % more than SHRINK time since last connect
                      logplex_msg_buffer:resize(?SHRINK_BUF_SIZE, Buf);
                  false ->
                      Buf
              end;
          false ->
              Buf
      end,
      %% We hibernate only when we need to reconnect with a timer. The timer
      %% acts as a rate limiter! If you remove the timer, you must re-think
      %% the hibernation.
      {next_state, disconnected,
       reconnect_in(timer:seconds(BackOff), State#state{buf=NewBuf}),
       hibernate}.
  
  reconnect_in(MS, State = #state{}) ->
      Ref = erlang:start_timer(MS, self(), ?RECONNECT_MSG),
  