public bool CanAccess(string pattern, string clientAddress, int maxRequests, LimitUnit unit)
        {
            CleanUpExpiredData();

            var requestKey = new RequestKey(pattern, clientAddress);

            if (!_requests.ContainsKey(requestKey))
            {
                _requests[requestKey] = new List <DateTime>();
            }

            var fromTime = unit switch
            {
                LimitUnit.Sec => _dateTime.Now.AddSeconds(-1),
                LimitUnit.Min => _dateTime.Now.AddMinutes(-1),
                LimitUnit.Hr => _dateTime.Now.AddHours(-1),
                _ => throw new ArgumentOutOfRangeException(nameof(unit), unit, null)
            };

            var totalRequestFromTime = _requests[requestKey].Count(x => x >= fromTime);

            // if an api must be throttled not need to add request and refresh timer
            if (totalRequestFromTime >= maxRequests)
            {
                return(false);
            }
            _requests[requestKey].Add(_dateTime.Now);
            return(true);
        }
Exemplo n.º 2
0
        protected override void Execute(CodeActivityContext context)
        {
            // Open the config file and get the connection string
            Configuration            config = WebConfigurationManager.OpenWebConfiguration("/RequestWeb");
            ConnectionStringsSection css    =
                (ConnectionStringsSection)config.GetSection("connectionStrings");
            string connectionString = css.ConnectionStrings["Request"].ConnectionString;

            // Lookup the Request
            RequestDataContext dc = new RequestDataContext(connectionString);
            Request            r  = dc.Requests.SingleOrDefault(x => x.RequestKey == RequestKey.Get(context));

            if (r == null)
            {
                throw new InvalidProgramException("The specified request (" + RequestKey.Get(context) + ") was not found");
            }

            r.QC               = true;
            r.AssignedDate     = DateTime.UtcNow;
            r.AssignedOperator = null;

            // Update the Request record
            PersistRequest persist = context.GetExtension <PersistRequest>();

            persist.AddRequest(r);
        }
Exemplo n.º 3
0
        public bool AsyncFetchContents(ChorusAccount chorusAccount, ChorusUrl chorusUrl, out ChorusServerException chorusException)
        {
            Uri requestUri = GetContentsUri(chorusAccount, chorusUrl);

            if (null == requestUri)
            {
                chorusException = null;
                return(true);
            }
            RequestKey requestKey = new RequestKey(chorusAccount, requestUri);

            lock (_lock)
            {
                ChorusContentsResponse chorusContentsResponse;
                if (_chorusContentsByServerUrl.TryGetValue(requestKey, out chorusContentsResponse))
                {
                    chorusException = chorusContentsResponse.ChorusException;
                    return(chorusContentsResponse.IsComplete);
                }
                chorusException = null;
                if (!_fetchRequests.Add(requestKey))
                {
                    return(false);
                }
            }
            ActionUtil.RunAsync(() => FetchAndStoreContents(chorusAccount, requestUri), "Fetch from Chorus");   // Not L10N
            return(false);
        }
Exemplo n.º 4
0
        public async Task <IActionResult> Download([ModelBinder(typeof(RequestKeyBinder))] RequestKey Key)
        {
            if (GetValidateResult() is IActionResult ErrorResult)
            {
                return(ErrorResult);
            }
            var Token = HttpContext.RequestAborted;

            try
            {
                var Path    = HttpContext.Request.Path + HttpContext.Request.QueryString;
                var Result  = new PipelineStreamResult();
                var Receive = await Store.GetReceiveAsync(Key, Token);

                await Receive.ConnectionAsync(Result, Token);

                return(Result);
            }
            catch (OperationCanceledException e)
            {
                if (Token.IsCancellationRequested)
                {
                    return(BadRequest(string.Format(CancelMessage, e.Message)));
                }
                return(BadRequest(string.Format(TimeoutMessage, ConnectionTimeout)));
            }
            catch (InvalidOperationException e)
            {
                Logger.LogError(e, DownloadFail);
                return(BadRequest(string.Format(ErrorMessage, e.Message)));
            }
        }
Exemplo n.º 5
0
 protected IEnumerable <IRequestHandler <I, O, S, C, A> > InitHandler <I, O>(RequestKey key, bool reset)
 {
     try
     {
         return((from t in GetHandlerTypes(reset)
                 let interfaces = t.GetTypeInfo().GetInterfaces()
                                  let attributes = t.GetTypeInfo().GetCustomAttributes(typeof(RequestHandlerAttribute))
                                                   where attributes.Any(attr => ((RequestHandlerAttribute)attr).Namespace == key.Namespace) &&
                                                   interfaces.Any(x => x.IsConstructedGenericType &&
                                                                  x.FullName == typeof(IRequestHandler <I, O, S, C, A>).FullName &&
                                                                  x.GetGenericArguments()[0] == key.InputType &&
                                                                  x.GetGenericArguments()[1] == key.OutputType &&
                                                                  x.GetGenericArguments()[2] == typeof(S) &&
                                                                  x.GetGenericArguments()[3] == typeof(C) &&
                                                                  x.GetGenericArguments()[4] == typeof(A))
                                                   select(IRequestHandler <I, O, S, C, A>) Activator.CreateInstance(t)).ToList());
     }
     catch (Exception e)
     {
         if (!reset)
         {
             return(InitHandler <I, O>(key, true));
         }
         else
         {
             var e2 = new ClientException($"no handler found for request {key.Namespace} {key.InputType.Name} {key.OutputType.Name}", e);
             e2.Data.Add("Key", key);
             throw e2;
         }
     }
 }
Exemplo n.º 6
0
        public static void InsertHeadersFromContextInto(HttpListenerContext _Context, Action <string, string> _CollectionAddFunction, string[] _ExcludeHeaderKeys = null)
        {
            if (_ExcludeHeaderKeys != null)
            {
                for (int i = 0; i < _ExcludeHeaderKeys.Length; i++)
                {
                    _ExcludeHeaderKeys[i] = _ExcludeHeaderKeys[i].ToLower();
                }
            }

            foreach (var RequestKey in _Context.Request.Headers.AllKeys)
            {
                var LoweredKey = RequestKey.ToLower();
                if (!IllegalHttpRequestHeaders.Contains(LoweredKey))
                {
                    if (_ExcludeHeaderKeys != null && _ExcludeHeaderKeys.Contains(LoweredKey))
                    {
                        continue;
                    }

                    var Values = _Context.Request.Headers.GetValues(RequestKey);
                    foreach (var Value in Values)
                    {
                        _CollectionAddFunction?.Invoke(RequestKey, Value);
                    }
                }
            }
        }
Exemplo n.º 7
0
        private void FetchAndStore <T>(Uri requestUri, Func <Uri, T> fetcher)
        {
            var key = new RequestKey(typeof(T), requestUri);

            try
            {
                var data = fetcher(requestUri);
                lock (_lock)
                {
                    _responses[key] = new RemoteResponse(data, null);
                }
            }
            catch (Exception exception)
            {
                RemoteServerException remoteException = exception as RemoteServerException;
                // ReSharper disable once ConvertIfStatementToNullCoalescingExpression
                if (null == remoteException)
                {
                    remoteException = new RemoteServerException(
                        Resources.RemoteSession_FetchContents_There_was_an_error_communicating_with_the_server__
                        + exception.Message, exception);
                }
                lock (_lock)
                {
                    _responses[key] = new RemoteResponse(null, remoteException);
                }
            }
            FireContentsAvailable();
        }
Exemplo n.º 8
0
 protected bool AsyncFetch <T>(Uri requestUri, Func <Uri, T> fetcher, out RemoteServerException remoteException)
 {
     if (null == requestUri)
     {
         remoteException = null;
         return(true);
     }
     lock (_lock)
     {
         RemoteResponse response;
         var            key = new RequestKey(typeof(T), requestUri);
         if (_responses.TryGetValue(key, out response))
         {
             remoteException = response.Exception;
             return(true);
         }
         remoteException = null;
         if (!_fetchRequests.Add(key))
         {
             return(false);
         }
     }
     ActionUtil.RunAsync(() => FetchAndStore(requestUri, fetcher));
     return(false);
 }
Exemplo n.º 9
0
        protected override void Execute(CodeActivityContext context)
        {
            // Get the connection string
            DBConnection ext = context.GetExtension <DBConnection>();

            if (ext == null)
            {
                throw new InvalidProgramException("No connection string available");
            }

            // Lookup the Request
            RequestDataContext dc = new RequestDataContext(ext.ConnectionString);
            Request            r  = dc.Requests.SingleOrDefault(x => x.RequestKey == RequestKey.Get(context));

            if (r == null)
            {
                throw new InvalidProgramException("The specified request (" + RequestKey.Get(context) + ") was not found");
            }

            // Update the Request record
            r.ActionTaken = ActionTaken.Get(context);
            r.RouteNext   = RouteNext.Get(context);

            PersistRequest persist = context.GetExtension <PersistRequest>();

            persist.AddRequest(r);

            context.SetValue(Request, r);
        }
Exemplo n.º 10
0
        private void FetchAndStoreContents(ChorusAccount chorusAccount, Uri requestUri)
        {
            ChorusContents contents = new ChorusContents();
            var            key      = new RequestKey(chorusAccount, requestUri);

            try
            {
                StoreContentsResponse(key, new ChorusContentsResponse(FetchContents(chorusAccount, requestUri), true));
            }
            catch (Exception exception)
            {
                ChorusServerException chorusException = exception as ChorusServerException;
                // ReSharper disable once ConvertIfStatementToNullCoalescingExpression
                if (null == chorusException)
                {
                    chorusException = new ChorusServerException(
                        Resources.ChorusSession_FetchContents_There_was_an_error_communicating_with_the_server__
                        + exception.Message, exception);
                }
                StoreContentsResponse(key, new ChorusContentsResponse(contents, true)
                {
                    ChorusException = chorusException,
                });
            }
            finally
            {
                lock (_lock)
                {
                    _fetchRequests.Remove(key);
                }
            }
        }
Exemplo n.º 11
0
        /**
         * When we get a reply ack, we can remove the item from our cache,
         * we know the other guy got our reply
         */
        protected void HandleReplyAck(ReqrepType rt, int idnum,
                                      MemBlock err_data, ISender ret_path)
        {
            RequestKey rk = new RequestKey(idnum, ret_path);

            lock ( _sync ) {
                /**
                 * This is not completely safe, but probably fine.  Consider the
                 * case where:
                 * A -(req)-> B
                 * A timeout but B does get the req
                 * A <-(rep)- B
                 * A -(req)-> B (these cross in flight)
                 * A -(repack)-> B
                 *
                 * but then the repack passes the req retransmission (out of order
                 * delivery)
                 *
                 * This is unlikely, but we could improve it.
                 * @todo improve the reply caching algorithm
                 */
                ReplyState rs = (ReplyState)_reply_cache[rk];
                if (rs != null)
                {
                    ReleaseReplyState(rs);
                }
            }
        }
Exemplo n.º 12
0
 public void Release(RequestKey requestKey)
 {
     if (_waitHandles.ContainsKey(requestKey))
     {
         _waitHandles.Remove(requestKey);
     }
 }
Exemplo n.º 13
0
        // Methods /////

        /** Create a ReplyState for a new Request
         * Note, this is not synchronized, you must hold the lock when calling!
         */
        protected ReplyState GenerateReplyState(PType prefix, RequestKey rk)
        {
            var rs = new ReplyState(_prefix, rk);

            _reply_cache[rk] = rs;
            rs.LocalID       = _reply_id_table.GenerateID(rs);
            return(rs);
        }
Exemplo n.º 14
0
        public void RequestKeyTest1(PathString path, IQueryCollection query, PathString ExpectedLocalPath, int ExpectedReceivers, string ExpectToString)
        {
            var Key = new RequestKey(path, query);

            Assert.AreEqual((string)ExpectedLocalPath, Key.Path);
            Assert.AreEqual(ExpectedReceivers, Key.Receivers);
            Assert.AreEqual(ExpectToString, Key.ToString());
        }
Exemplo n.º 15
0
 public HomeController(
     IHttpContextAccessor httpContextAccessor,
     IHostingEnvironment hostingEnvironment,
     RequestKey requestKey)
 {
     this.HttpContextAccessor = httpContextAccessor;
     this.HostingEnvironment  = hostingEnvironment;
     this.RequestKey          = requestKey;
 }
Exemplo n.º 16
0
 public void Release <TResult>(RequestKey key, TResult result)
 {
     lock (this)
     {
         var waitHandle = (RequestWaitHandle <TResult>)_waitHandles[key];
         _waitHandles.Remove(key);
         waitHandle.Release(result);
     }
 }
Exemplo n.º 17
0
 public void ReleaseWithException <TResult>(RequestKey key, Exception thrownException)
 {
     lock (this)
     {
         var waitHandle = (RequestWaitHandle <TResult>)_waitHandles[key];
         _waitHandles.Remove(key);
         waitHandle.ReleaseWithException(thrownException);
     }
 }
Exemplo n.º 18
0
 public ReplyState(PType prefix, RequestKey rk)
 {
     _prefix         = prefix;
     RequestKey      = rk;
     RequestDate     = DateTime.UtcNow;
     _reply_timeouts = 0;
     _uri            = new WriteOnce <string>();
     _lid            = 0;
 }
Exemplo n.º 19
0
 public HomeController(
     IHttpContextAccessor httpContextAccessor,
     GracefullShutdownState gracefullShutdownState,
     RequestKey requestKey)
 {
     HttpContextAccessor    = httpContextAccessor;
     GracefullShutdownState = gracefullShutdownState;
     RequestKey             = requestKey;
 }
Exemplo n.º 20
0
        protected void HandleRequest(ReqrepType rt, int idnum,
                                     MemBlock rest, ISender retpath)
        {
            /**
             * Lets see if we have been asked this question before
             */
            ReplyState rs     = null;
            bool       resend = false;

#if REQREP_DEBUG
            Console.Error.WriteLine("[ReqrepManager: {0}] Receiving request id: {1}, from: {2}",
                                    _info, idnum, retpath);
#endif
            RequestKey rk = new RequestKey(idnum, retpath);
            lock ( _sync ) {
                rs = (ReplyState)_reply_cache[rk];
                if (rs == null)
                {
                    rs = GenerateReplyState(_prefix, rk);
                }
                else
                {
                    resend = true;
                }
            }
            if (resend)
            {
                //This is an old request:
                rs.Resend();
            }
            else
            {
                //This is a new request:
                try {
                    _sub.Handle(rest, rs);
                }
                catch {
                    lock ( _sync ) {
                        ReleaseReplyState(rs);
                    }
                    //This didn't work out:
                    try {
                        MemBlock err_data = MemBlock.Reference(
                            new byte[] { (byte)ReqrepError.HandlerFailure });
                        ICopyable reply = MakeRequest(ReqrepType.Error, idnum, err_data);
                        retpath.Send(reply);
                    }
                    catch {
                        //If this fails, we may think about logging.
                        //The return path could fail, that's the only obvious exception
                        ///@todo log exception
                    }
                }
            }
        }
Exemplo n.º 21
0
        private void StoreContentsResponse(RequestKey key, ChorusContentsResponse chorusContentsResponse)
        {
            lock (_lock)
            {
                _chorusContentsByServerUrl[key] = chorusContentsResponse;
            }
            var contentsAvailableEvent = ContentsAvailable;

            if (null != contentsAvailableEvent)
            {
                contentsAvailableEvent();
            }
        }
Exemplo n.º 22
0
 public IRequestHandler <I, O, S, C, A> GetHandler <I, O>(IRequest <I, O> request)
 {
     // get or initialise handler. Safe to cast because init is generic.
     return(((IEnumerable <IRequestHandler <I, O, S, C, A> >)handlers
             .GetOrAdd(RequestKey.ForRequest(request), key =>
     {
         return InitHandler <I, O>(key);
     })).OrderBy(handler =>
     {
         RequestHandlerPriorityAttribute attr = handler.GetType().GetTypeInfo().GetCustomAttribute <RequestHandlerPriorityAttribute>();
         return attr == null ? 0 : attr.Priority;
     }).Where(handler => (handler is IConditionalHandler) ? ((IConditionalHandler)handler).CanHandle(request.Content) : true)
            .First());
 }
Exemplo n.º 23
0
        protected override void Execute(CodeActivityContext context)
        {
            // Open the config file and get the connection string
            Configuration            config = WebConfigurationManager.OpenWebConfiguration("/RequestWeb");
            ConnectionStringsSection css    =
                (ConnectionStringsSection)config.GetSection("connectionStrings");
            string connectionString = css.ConnectionStrings["Request"].ConnectionString;

            // Lookup the Queue
            RequestDataContext dc = new RequestDataContext(connectionString);
            Queue  q     = null;
            string queue = QueueName.Get(context);

            if (queue != null && queue.Length > 0 && queue != "None")
            {
                q = dc.Queues.SingleOrDefault(x => x.QueueName == QueueName.Get(context));
                if (q == null)
                {
                    throw new InvalidProgramException("The specified queue (" + QueueName.Get(context) + ") was not found");
                }
            }

            // Lookup the Request
            Request r = dc.Requests.SingleOrDefault(x => x.RequestKey == RequestKey.Get(context));

            if (r == null)
            {
                throw new InvalidProgramException("The specified request (" + RequestKey.Get(context) + ") was not found");
            }

            if (q != null)
            {
                r.CurrentQueueID   = q.QueueID;
                r.AssignedDate     = DateTime.UtcNow;
                r.AssignedOperator = null;
            }
            else
            {
                r.CurrentQueueID   = null;
                r.AssignedDate     = null;
                r.AssignedOperator = null;
            }

            // Update the Request record
            PersistRequest persist = context.GetExtension <PersistRequest>();

            persist.AddRequest(r);
        }
Exemplo n.º 24
0
        public bool TryGetAwaitable <TResult>(RequestKey key, Func <Task <TResult> > loaderTask, out Task <TResult> awaitable)
        {
            object awaitableTask;

            if (_waitHandles.TryGetValue(key, out awaitableTask))
            {
                awaitable = (Task <TResult>)awaitableTask;
                return(true);
            }
            else
            {
                awaitable         = loaderTask();
                _waitHandles[key] = awaitable;
                return(false);
            }
        }
Exemplo n.º 25
0
            public override bool Equals(object o)
            {
                if (o == this)
                {
                    return(true);
                }
                RequestKey rk = o as RequestKey;

                if (rk != null)
                {
                    return((rk.RequestID == this.RequestID) && rk.Sender.Equals(this.Sender));
                }
                else
                {
                    return(false);
                }
            }
Exemplo n.º 26
0
        public async ValueTask <IActionResult> Options([ModelBinder(typeof(RequestKeyBinder))] RequestKey Key)
        {
            var Token = HttpContext.RequestAborted;

            if (Option.EnableContentOfHeadMethod)
            {
                return(Options());
            }
            var AccessControlAllowMethods = await Store.GetOptionMethodsAsync(Key, Token);

            var Headers = HttpContext.Response.Headers;

            Headers.Add("Access-Control-Allow-Origin", "*");
            Headers.Add("Access-Control-Allow-Methods", string.Join(", ", AccessControlAllowMethods));
            Headers.Add("Access-Control-Max-Age", "-1");
            throw new NotImplementedException();
        }
Exemplo n.º 27
0
        public bool ShouldWaitForHandle <TResult>(RequestKey key, out RequestWaitHandle <TResult> waitHandle)
        {
            lock (this)
            {
                object waitHandleObject;
                if (_waitHandles.TryGetValue(key, out waitHandleObject))
                {
                    waitHandle = (RequestWaitHandle <TResult>)waitHandleObject;
                    return(true);
                }

                waitHandle        = new RequestWaitHandle <TResult>();
                _waitHandles[key] = waitHandle;

                return(false);
            }
        }
Exemplo n.º 28
0
        protected void RetryFetch <T>(Uri requestUri, Func <Uri, T> fetcher)
        {
            if (requestUri == null)
            {
                return;
            }
            var key = new RequestKey(typeof(T), requestUri);

            lock (_lock)
            {
                if (_fetchRequests.Contains(key))
                {
                    return;
                }
                _responses.Remove(key);
                RemoteServerException exceptionIgnore;
                AsyncFetch(requestUri, fetcher, out exceptionIgnore);
            }
        }
Exemplo n.º 29
0
        public void RetryFetchContents(ChorusAccount chorusAccount, ChorusUrl chorusUrl)
        {
            Uri requestUri = GetContentsUri(chorusAccount, chorusUrl);

            if (null == requestUri)
            {
                return;
            }
            RequestKey requestKey = new RequestKey(chorusAccount, requestUri);

            lock (_lock)
            {
                if (_fetchRequests.Contains(requestKey))
                {
                    return;
                }
                _chorusContentsByServerUrl.Remove(requestKey);
                ChorusServerException exceptionIgnore;
                AsyncFetchContents(chorusAccount, chorusUrl, out exceptionIgnore);
            }
        }
Exemplo n.º 30
0
 public IRequestHandler <I, O, S, C, A> GetHandler <I, O>(IRequest <I, O> request)
 {
     // get or initialise handler. Safe to cast because init is generic.
     try
     {
         return(((IEnumerable <IRequestHandler <I, O, S, C, A> >)handlers
                 .GetOrAdd(RequestKey.ForRequest(request), key =>
         {
             return InitHandler <I, O>(key, false);
         })).OrderBy(handler =>
         {
             RequestHandlerPriorityAttribute attr = handler.GetType().GetTypeInfo().GetCustomAttribute <RequestHandlerPriorityAttribute>();
             return attr == null ? 0 : attr.Priority;
         }).Where(handler => (handler is IConditionalHandler) ? ((IConditionalHandler)handler).CanHandle(request.Content) : true)
                .First());
     }
     catch (InvalidOperationException e)
     {
         throw new ClientException($"No handler found for request {request.Namespace} {typeof(I).Name} {typeof(O).Name}", e);
     }
 }
Exemplo n.º 31
0
 public ReplyState(RequestKey rk) {
   RequestKey = rk;
   RequestDate = DateTime.UtcNow;
   _reply_timeouts = 0;
   _uri = new WriteOnce<string>();
   _lid = 0;
 }
Exemplo n.º 32
0
 public ReplyState(RequestKey rk) {
   RequestKey = rk;
   RequestDate = DateTime.UtcNow;
   _reply_timeouts = 0;
 }
Exemplo n.º 33
0
 public ReplyState(PType prefix, RequestKey rk) {
   _prefix = prefix;
   RequestKey = rk;
   RequestDate = DateTime.UtcNow;
   _reply_timeouts = 0;
   _uri = new WriteOnce<string>();
   _lid = 0;
 }
Exemplo n.º 34
0
   // Methods /////

   /** Create a ReplyState for a new Request
    * Note, this is not synchronized, you must hold the lock when calling!
    */
   protected ReplyState GenerateReplyState(PType prefix, RequestKey rk) {
     var rs = new ReplyState(_prefix, rk);
     _reply_cache[rk] = rs;
     rs.LocalID = _reply_id_table.GenerateID(rs);
     return rs;
   }
Exemplo n.º 35
0
 /**
  * When we get a reply ack, we can remove the item from our cache,
  * we know the other guy got our reply
  */
 protected void HandleReplyAck(ReqrepType rt, int idnum,
                            MemBlock err_data, ISender ret_path) {
   RequestKey rk = new RequestKey(idnum, ret_path);
   lock( _sync ) {
     /**
      * This is not completely safe, but probably fine.  Consider the
      * case where:
      * A -(req)-> B 
      * A timeout but B does get the req
      * A <-(rep)- B
      * A -(req)-> B (these cross in flight)
      * A -(repack)-> B
      *
      * but then the repack passes the req retransmission (out of order
      * delivery)
      *
      * This is unlikely, but we could improve it.
      * @todo improve the reply caching algorithm
      */
     ReplyState rs = (ReplyState)_reply_cache[rk]; 
     if( rs != null ) {
       ReleaseReplyState(rs);
     }
   }
 }
Exemplo n.º 36
0
   protected void HandleRequest(ReqrepType rt, int idnum,
                                MemBlock rest, ISender retpath)
   {
     /**
      * Lets see if we have been asked this question before
      */
     ReplyState rs = null;
     bool resend = false;
#if REQREP_DEBUG
	 Console.Error.WriteLine("[ReqrepManager: {0}] Receiving request id: {1}, from: {2}", 
			     _info, idnum, retpath);
#endif
     RequestKey rk = new RequestKey(idnum, retpath);
     lock( _sync ) {
       rs = (ReplyState)_reply_cache[rk];
       if( rs == null ) {
         rs = GenerateReplyState(_prefix, rk);
       }
       else {
         resend = true;
       }
     }
     if( resend ) {
       //This is an old request:
       rs.Resend();
     }
     else {
       //This is a new request:
       try {
         _sub.Handle(rest, rs);
       }
       catch {
         lock( _sync ) {
           ReleaseReplyState(rs);
         }
         //This didn't work out:
         try {
           MemBlock err_data = MemBlock.Reference(
                        new byte[]{ (byte) ReqrepError.HandlerFailure } );
           ICopyable reply = MakeRequest(ReqrepType.Error, idnum, err_data);
           retpath.Send(reply);
         }
         catch {
           //If this fails, we may think about logging.
           //The return path could fail, that's the only obvious exception
           ///@todo log exception
         }
       }
     }
   }