anchor.diff:  %%--------------------------------------------------------------------
   -spec gateway_loop(State :: #{atom() => term()}) -> no_return().
   gateway_loop(#{port_fd := PortFD, id := {_, N} = ID, db_hostname := Hostname, db_port := Port, gw_port := GWPort,
  -    start_time := ST, parent := Parent} = State) ->
  +    start_time := ST, parent := Parent, last_ping_time := LPT} = State) ->
   
       %% Update state
       Gateways = datastore_worker:state_get(db_gateways),
       datastore_worker:state_put(db_gateways, maps:update(N, State, Gateways)),
   
  -    try port_command(PortFD, <<"ping">>) of
  +    UpdatedState = case erlang:system_time(milli_seconds) - LPT > timer:seconds(1) of
           true ->
  -            try couchbeam:server_info(catch couchbeam:server_connection("localhost", GWPort)) of
  -                {ok, _} -> ok;
  -                {error, Reason00} ->
  -                    self() ! {port_comm_error, Reason00}
  +            try
  +                true = port_command(PortFD, <<"ping">>, [nosuspend]),
  +                {ok, _} = couchbeam:server_info(catch couchbeam:server_connection("localhost", GWPort)),
  +                State#{last_ping_time => erlang:system_time(milli_seconds)}
               catch
                   _:{badmap, undefined} ->
  -                    ok; %% State of the worker may not be initialised yet, so there is not way to check if connection is active
  -                _:Reason01 ->
  -                    self() ! {port_comm_error, Reason01}
  -            end
  -    catch
  -        _:Reason0 ->
  -            self() ! {port_comm_error, Reason0}
  +                    State; %% State of the worker may not be initialised yet, so there is not way to check if connection is active
  +                _:Reason0 ->
  +                    self() ! {port_comm_error, Reason0},
  +                    State
  +            end;
  +        false ->
  +            State
       end,
   
       CT = erlang:system_time(milli_seconds),
  
positive.code:         receive
              {PortFD, {data, {_, Data}}} ->
                  case binary:matches(Data, <<"HTTP:">>) of
                      [] ->
                          ?info("[CouchBase Gateway ~p] ~s", [ID, Data]);
                      _ -> ok
                  end,
                  State;
              {PortFD, closed} ->
                  State#{status => closed};
  
              {'EXIT', PortFD, Reason} ->
                  ?error("CouchBase gateway's port ~p exited with reason: ~p", [State, Reason]),
                  State#{status => failed};
              {port_comm_error, Reason} ->
                  ?error("[CouchBase Gateway ~p] Unable to communicate with port due to: ~p", [ID, Reason]),
                  State#{status => failed};
              restart when CT > MinRestartTime ->
                  ?info("[CouchBase Gateway ~p] Restart request...", [ID]),
                  State#{status => restarting};
              restart ->
                  State;
              {'DOWN', _, process, Parent, Reason} ->
                      catch port_close(PortFD),
                  State#{status => closed};
              stop ->
                      catch port_close(PortFD),
                  State#{status => closed};
              Other ->
                  ?warning("[CouchBase Gateway ~p] ~p", [ID, Other]),
                  State
          after timer:seconds(1) ->
              State
          end,
      case NewState of
          #{status := running} ->
  
negative.code:     State = #{
          server => self(), port_fd => PortFD, status => init, id => {node(), N},
          gw_port => GWPort, gw_admin_port => GWAdminPort, db_hostname => Hostname, db_port => Port,
          start_time => erlang:system_time(milli_seconds), parent => Parent, last_ping_time => -1
      },
      monitor(process, Parent),
      proc_lib:init_ack(Parent, State),
  