markmcdowell / NLog.Targets.ElasticSearch

NLog target for Elasticsearch
MIT License
176 stars 89 forks source link

Stackoverflow Exception #114

Closed barengin closed 4 years ago

barengin commented 4 years ago

Hello,

I am receiving StackOverflowException on _client_Bulk method. It's interesting because I don't receive it all the time but mostly. Any idea? (I'm using elastic.co)

Thanks

private void SendBatch(ICollection<AsyncLogEventInfo> logEvents)
        {
            try
            {
                var payload = FormPayload(logEvents);
                var result = _client.Bulk<BytesResponse>(payload);
                var exception = result.Success ? null : result.OriginalException ?? new Exception("No error message. Enable Trace logging for more information.");
                if (exception != null)
                {
                    InternalLogger.Error(exception.FlattenToActualException(), $"ElasticSearch: Failed to send log messages. status={result.HttpStatusCode}");
                }

                foreach (var ev in logEvents)
                {
                    ev.Continuation(exception);
                }
            }
            catch (Exception ex)
            {
                InternalLogger.Error(ex.FlattenToActualException(), "ElasticSearch: Error while sending log messages");
                foreach (var ev in logEvents)
                {
                    ev.Continuation(ex);
                }
            }
        }
markmcdowell commented 4 years ago

It can be because of a cyclic object being logged (quite often exceptions are cyclic), do you see anything in the internal logging when it happens?

barengin commented 4 years ago

Yes, I've seen the problem after I clicked the submit button. You are right. there is a cyclic object.

Thanks.