Skip to content

Commit 769dc7b

Browse files
committed
Fixed an issue where events wouldn't be submitted due to a large batch size.
1 parent 5b4d9b4 commit 769dc7b

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

Source/Shared/Configuration/ExceptionlessConfiguration.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,25 @@ namespace Exceptionless {
1010
public class ExceptionlessConfiguration {
1111
private const string DEFAULT_SERVER_URL = "https://collector.exceptionless.io";
1212
private const string DEFAULT_USER_AGENT = "exceptionless/" + ThisAssembly.AssemblyFileVersion;
13+
private const int DEFAULT_SUBMISSION_BATCH_SIZE = 50;
14+
1315
private readonly IDependencyResolver _resolver;
1416
private bool _configLocked;
1517
private string _apiKey;
1618
private string _serverUrl;
19+
private int _submissionBatchSize;
1720
private ValidationResult _validationResult;
1821
private readonly List<string> _exclusions = new List<string>();
1922

2023
public ExceptionlessConfiguration(IDependencyResolver resolver) {
2124
ServerUrl = DEFAULT_SERVER_URL;
2225
UserAgent = DEFAULT_USER_AGENT;
26+
SubmissionBatchSize = DEFAULT_SUBMISSION_BATCH_SIZE;
2327
Enabled = true;
2428
EnableSSL = true;
2529
DefaultTags = new TagSet();
2630
DefaultData = new DataDictionary();
2731
Settings = new SettingsDictionary();
28-
SubmissionBatchSize = 50;
2932
if (resolver == null)
3033
throw new ArgumentNullException("resolver");
3134
_resolver = resolver;
@@ -120,7 +123,13 @@ public string ApiKey {
120123
/// <summary>
121124
/// Maximum number of events that should be sent to the server together in a batch. (Defaults to 50)
122125
/// </summary>
123-
public int SubmissionBatchSize { get; set; }
126+
public int SubmissionBatchSize {
127+
get { return _submissionBatchSize; }
128+
set {
129+
if (value > 0)
130+
_submissionBatchSize = value;
131+
}
132+
}
124133

125134
/// <summary>
126135
/// A list of exclusion patterns that will automatically remove any data that matches them from any data submitted to the server.

Source/Shared/Queue/DefaultEventQueue.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ public void Process() {
6565
_storage.ReleaseStaleLocks(_config.GetQueueName());
6666

6767
DateTime maxCreatedDate = DateTime.Now;
68-
var batch = _storage.GetEventBatch(_config.GetQueueName(), _serializer, _config.SubmissionBatchSize, maxCreatedDate);
68+
int batchSize = _config.SubmissionBatchSize;
69+
var batch = _storage.GetEventBatch(_config.GetQueueName(), _serializer, batchSize, maxCreatedDate);
6970
while (batch.Any()) {
7071
bool deleteBatch = true;
7172

@@ -90,6 +91,14 @@ public void Process() {
9091
// The service end point could not be found.
9192
_log.FormattedError(typeof(DefaultEventQueue), "Error while trying to submit data: {0}", response.Message);
9293
SuspendProcessing(TimeSpan.FromHours(4));
94+
} else if (response.RequestEntityTooLarge) {
95+
if (batchSize > 1) {
96+
_log.Error(typeof(DefaultEventQueue), "Event submission discarded for being too large. The event will be retried with a smaller batch size.");
97+
batchSize = Math.Max(1, (int)Math.Round(batchSize / 1.5d, 0));
98+
deleteBatch = false;
99+
} else {
100+
_log.Error(typeof(DefaultEventQueue), "Event submission discarded for being too large. The event will not be submitted.");
101+
}
93102
} else if (!response.Success) {
94103
_log.Error(typeof(DefaultEventQueue), String.Format("An error occurred while submitting events: {0}", response.Message));
95104
SuspendProcessing();
@@ -113,7 +122,7 @@ public void Process() {
113122
if (!deleteBatch || IsQueueProcessingSuspended)
114123
break;
115124

116-
batch = _storage.GetEventBatch(_config.GetQueueName(), _serializer, _config.SubmissionBatchSize, maxCreatedDate);
125+
batch = _storage.GetEventBatch(_config.GetQueueName(), _serializer, batchSize, maxCreatedDate);
117126
}
118127
} catch (Exception ex) {
119128
_log.Error(typeof(DefaultEventQueue), ex, String.Concat("An error occurred while processing the queue: ", ex.Message));

Source/Shared/Submission/SubmissionResponse.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public SubmissionResponse(int statusCode, string message = null) {
2222
PaymentRequired = (HttpStatusCode)statusCode == HttpStatusCode.PaymentRequired;
2323
UnableToAuthenticate = (HttpStatusCode)statusCode == HttpStatusCode.Unauthorized || (HttpStatusCode)statusCode == HttpStatusCode.Forbidden;
2424
NotFound = (HttpStatusCode)statusCode == HttpStatusCode.NotFound;
25+
RequestEntityTooLarge = (HttpStatusCode)statusCode == HttpStatusCode.RequestEntityTooLarge;
2526
}
2627

2728
public bool Success { get; private set; }
@@ -30,6 +31,7 @@ public SubmissionResponse(int statusCode, string message = null) {
3031
public bool PaymentRequired { get; private set; }
3132
public bool UnableToAuthenticate { get; private set; }
3233
public bool NotFound { get; private set; }
34+
public bool RequestEntityTooLarge { get; private set; }
3335

3436
public int StatusCode { get; private set; }
3537
public string Message { get; private set; }

0 commit comments

Comments
 (0)