Comments (3)
The issue reported by @sanderweltje highlights how easy it is to write bug-free concurrent code.
The continuation used in the ProcessQueueAsync(MessageBuilder messageBuilder)
method might seem the proper solution to take care of any exception raised in the ProcessQueueAsync(MessageBuilder messageBuilder, TaskCompletionSource<object> tcs)
method:
private void ProcessQueueAsync(MessageBuilder messageBuilder)
{
ProcessQueueAsync(messageBuilder, new TaskCompletionSource<object>())
.ContinueWith(t =>
{
InternalLogger.Warn(t.Exception?.GetBaseException(), "[Syslog] ProcessQueueAsync faulted within try");
ProcessQueueAsync(messageBuilder);
}, token, TaskContinuationOptions.ExecuteSynchronously | TaskContinuationOptions.OnlyOnFaulted, TaskScheduler.Current);
}
Unfortunately due to the fact that the same CancellationToken
is used everywhere, the ContinueWith
does not execute the continuation function if the token
has been cancelled.
from nlog.targets.syslog.
If the CancellationToken is used to cancel all processing, the reuse of the token is correct. If the CancellationToken is also used for other purposes, a second CancellationToken might be a better solution. In case you want to cancel all processing and an exception is thrown, you probably don't want to restart ProcessQueueAsync(messageBuilder)
from nlog.targets.syslog.
I already use multiple tokens for different purposes, but the issue was caused by the one used to stop processing, because it was passed to all ContinueWith
, preventing exceptions from being observed if thrown after a cancellation.
Considering the logical workflow it does not make sense to continue processing when a cancellation is triggered, but, due to the way ContinueWith
interacts with CancellationToken
(here some tests), relying on the first successful detection of the cancellation i.e. if (token.IsCancellationRequested)
, allows to achieve the expected graceful termination.
from nlog.targets.syslog.
Related Issues (20)
- Offline UPD server not triggering reconnect HOT 1
- The community profile is incomplete
- NuGet API key expired
- Name of wrapped target has "_wrapped" suffix HOT 3
- Infinite retries and potential log entries lost upon delivery failure HOT 2
- Delivery issues result in infinite retries HOT 1
- Delivery issues can result in lost log entries HOT 4
- Superfluous catch of OperationCanceledException
- Support for .NET Framework not needed
- Multiple build services are used
- How to get started is missing HOT 1
- Extensions section missing in sample configuration HOT 1
- NLog version in README is wrong
- Build badges in README are not relevant
- NuGet publication fails with Powershell error
- NuGet publication unable to find packages
- Is the target compatible with the new NLog extension configuration? HOT 32
- Improper dependency handling with .NET Framework application HOT 5
- structured logging - Escaping special characters for ${all-event-properties} layout renderer HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nlog.targets.syslog.