anchor.diff:                  {reply, Response, NewState0} ->
                       %% Send reply and get ready for the next request - send the next request
                       %% if one is queued up
  -                    NewState1 = send_caller(Response, NewState0),
  -                    NewState = dequeue_request(NewState1#state{pending = undefined});
  +                    cancel_req_timer(Pending#request.tref),
  +                    send_caller(Response, NewState0#state.pending),
  +                    NewState = dequeue_request(NewState0#state{pending = undefined});
   
                   {noreply, NewState0} ->
                       %% Request has completed with no reply needed, send the next request 
                       %% if one is queued up
  +                    cancel_req_timer(Pending#request.tref),
                       NewState = dequeue_request(NewState0#state{pending = undefined});
   
  -                {pending, NewState} ->
  -                    ok %% Request is still pending - do not queue up a new one
  +                {pending, NewState0} -> %% Request is still pending - do not queue up a new one
  +                    NewPending = restart_req_timer(Pending),
  +                    NewState = NewState0#state{pending = NewPending}
               end
       end,
       inet:setopts(Sock, [{active, once}]),
       {noreply, NewState};
  +handle_info({req_timeout, Ref}, State) ->
  +    case State#state.pending of %%
  +        undefined ->
  +            {noreply, remove_queued_request(Ref, State)};
  +        Pending ->
  +            case Ref == Pending#request.ref of
  +                true ->  %% Matches the current operation
  +                    NewState = maybe_reply(on_timeout(State#state.pending, State)),
  +                    {noreply, disconnect(NewState#state{pending = undefined})};
  +                false ->
  +                    {noreply, remove_queued_request(Ref, State)}
  +            end
  +    end;
   handle_info(_, State) ->
       {noreply, State}.
   
  
positive.code:                  ?assertEqual({error,<<"{'query',{\"Query takes a list of step tuples\",undefined}}">>},
                                Res)
               end)}
  
       ].
  
  -endif.
  
negative.code:             State;
          {{value, Request}, Q2} ->
              send_request(Request, State#state{queue = Q2})
      end.
  
  %% Remove a queued request by reference - returns same queue if ref not present
  %% @private
  remove_queued_request(Ref, State) ->
      L = queue:to_list(State#state.queue),
      case lists:keytake(Ref, #request.ref, L) of
          false -> % Ref not queued up
              State;
          {value, Req, L2} ->
              {reply, Reply, NewState} = on_timeout(Req, State),
              send_caller(Reply, Req),
              NewState#state{queue = queue:from_list(L2)}
      end.
  
  %% @private
  