FATAL NServiceBus.Features.LicenseReminder Failed to initialize the license


(Peter) #1

Hi All,

I am using:
NSB 6.4.2
app hosted as windows service

We used some scheduler that initializes a couple of endpoints and sends messages to the queue by some schedule.
Endpoints configured as Send-only!
When several threads try to initialize endpoint in the same time I retrieve an error:
FATAL NServiceBus.Features.LicenseReminder Failed to initialize the license

2018-09-25 02:00:03.786 FATAL NServiceBus.Features.LicenseReminder Failed to initialize the license
System.IndexOutOfRangeException: Probable I/O race condition detected while copying memory. The I/O package is not thread safe by default. In multithreaded applications, a stream must be accessed in a thread-safe way, such as a thread-safe wrapper returned by TextReader’s or TextWriter’s Synchronized methods. This also applies to classes like StreamWriter and StreamReader.
at System.Buffer.InternalBlockCopy(Array src, Int32 srcOffsetBytes, Array dst, Int32 dstOffsetBytes, Int32 byteCount)
at System.IO.StreamWriter.Write(Char[] buffer, Int32 index, Int32 count)
at System.IO.TextWriter.SyncTextWriter.Write(Char[] buffer, Int32 index, Int32 count)
at System.Diagnostics.TextWriterTraceListener.WriteLine(String message)
at System.Diagnostics.TraceInternal.WriteLine(String message)
at NServiceBus.DefaultLoggerFactory.Write(String name, LogLevel messageLevel, String message) in C:\BuildAgent\work\a93f853f0c1b9532\src\NServiceBus.Core\Logging\DefaultLoggerFactory.cs:line 50
at NServiceBus.LicenseManager.LogFindResults(ActiveLicenseFindResult result) in C:\BuildAgent\work\a93f853f0c1b9532\src\NServiceBus.Core\Licensing\LicenseManager.cs:line 64
at NServiceBus.LicenseManager.InitializeLicense(String licenseText, String licenseFilePath) in C:\BuildAgent\work\a93f853f0c1b9532\src\NServiceBus.Core\Licensing\LicenseManager.cs:line 24
at NServiceBus.Features.LicenseReminder.Setup(FeatureConfigurationContext context) in C:\BuildAgent\work\a93f853f0c1b9532\src\NServiceBus.Core\Licensing\LicenseReminder.cs:line 21

As result after this exception, I could not initialize any new endpoint until restart service.
Any ideas?

(Andreas Öhlund) #2

It seems like the DefaultLogger isn’t thread safe, would you be able to try a different logger to verify?


How often does this happen?

(Andreas Öhlund) #3

Also can you share the code that is starting those endpoints?

(Simon Cropp) #4

according to this Trace.WriteLine is thread safe https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.trace?redirectedfrom=MSDN&view=netframework-4.7.2#thread-safety

but looking at a similar error (https://github.com/NimbusAPI/Nimbus/issues/242) my guess is it is a bug in the .net framework

@peter the default logging implementation is mean to be a MVP in terms of production usage. you should probably consider moving to another logging lib https://docs.particular.net/components/#loggers

(Andreas Öhlund) #5

@peter did you get this sorted out? did you switch logger?

(Peter) #6

@andreasohlund yeap, we have used NLog, and looks like all working properly, thank you.