diff --git a/src/Orleans.Runtime/Messaging/MessageCenter.cs b/src/Orleans.Runtime/Messaging/MessageCenter.cs index fc7bd0ee0f..a5527e6739 100644 --- a/src/Orleans.Runtime/Messaging/MessageCenter.cs +++ b/src/Orleans.Runtime/Messaging/MessageCenter.cs @@ -204,10 +204,20 @@ public bool TrySendLocal(Message message) internal void SendRejection(Message msg, Message.RejectionTypes rejectionType, string reason) { MessagingStatisticsGroup.OnRejectedMessage(msg); - if (string.IsNullOrEmpty(reason)) reason = string.Format("Rejection from silo {0} - Unknown reason.", MyAddress); - Message error = this.messageFactory.CreateRejectionResponse(msg, rejectionType, reason); - // rejection msgs are always originated in the local silo, they are never remote. - this.OnReceivedMessage(error); + + if (msg.Direction == Message.Directions.Response && msg.Result == Message.ResponseTypes.Rejection) + { + // Do not send reject a rejection locally, it will create a stack overflow + MessagingStatisticsGroup.OnDroppedSentMessage(msg); + if (this.log.IsEnabled(LogLevel.Debug)) log.Debug("Dropping rejection {msg}", msg); + } + else + { + if (string.IsNullOrEmpty(reason)) reason = $"Rejection from silo {this.MyAddress} - Unknown reason."; + var error = this.messageFactory.CreateRejectionResponse(msg, rejectionType, reason); + // rejection msgs are always originated in the local silo, they are never remote. + this.OnReceivedMessage(error); + } } public void RegisterLocalMessageHandler(IncomingMessageHandler handler)