Skip to content
This repository was archived by the owner on May 22, 2025. It is now read-only.

Commit 531d08d

Browse files
authored
Merge pull request #34 from launchdarkly/drichelson/ch934/net-sdk-stringcontent-disposed-exception
Better handling of errors when sending events
2 parents c6ad822 + a401781 commit 531d08d

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
All notable changes to the LaunchDarkly .NET SDK will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org).
44

5+
## [3.1.1] - 2017-01-16
6+
### Changed
7+
- Improved error handling when sending events
8+
59
## [3.1.0] - 2016-12-07
610
### Added
711
- Configurable http request timeout

src/LaunchDarkly.Client/EventProcessor.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,13 @@ void IStoreEvents.Flush()
6868
private async Task BulkSubmitAsync(IList<Event> events)
6969
{
7070
var cts = new CancellationTokenSource(_config.HttpClientTimeout);
71-
StringContent stringContent = null;
71+
var jsonEvents = "";
7272
try
7373
{
74-
var json = JsonConvert.SerializeObject(events.ToList(), Formatting.None);
75-
stringContent = new StringContent(json, Encoding.UTF8, "application/json");
74+
jsonEvents = JsonConvert.SerializeObject(events.ToList(), Formatting.None);
7675
Logger.LogDebug("Submitting " + events.Count + " events to " + _uri.AbsoluteUri + " with json: " +
77-
stringContent);
78-
await SendEventsAsync(stringContent, cts);
76+
jsonEvents);
77+
await SendEventsAsync(jsonEvents, cts);
7978
}
8079
catch (Exception e)
8180
{
@@ -90,8 +89,8 @@ private async Task BulkSubmitAsync(IList<Event> events)
9089
try
9190
{
9291
Logger.LogDebug("Submitting " + events.Count + " events to " + _uri.AbsoluteUri + " with json: " +
93-
stringContent);
94-
await SendEventsAsync(stringContent, cts);
92+
jsonEvents);
93+
await SendEventsAsync(jsonEvents, cts);
9594
}
9695
catch (TaskCanceledException tce)
9796
{
@@ -124,9 +123,10 @@ private async Task BulkSubmitAsync(IList<Event> events)
124123
}
125124

126125

127-
private async Task SendEventsAsync(StringContent content, CancellationTokenSource cts)
126+
private async Task SendEventsAsync(String jsonEvents, CancellationTokenSource cts)
128127
{
129-
using (var response = await _httpClient.PostAsync(_uri, content).ConfigureAwait(false))
128+
using (var stringContent = new StringContent(jsonEvents, Encoding.UTF8, "application/json"))
129+
using (var response = await _httpClient.PostAsync(_uri, stringContent).ConfigureAwait(false))
130130
{
131131
if (!response.IsSuccessStatusCode)
132132
{

src/LaunchDarkly.Client/project.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,5 @@
2828
}
2929
}
3030
},
31-
"version": "3.1.0"
31+
"version": "3.1.1"
3232
}

0 commit comments

Comments
 (0)