Why Hangfire job break when try to use NLog service? - fatal-error

My boss got error on his laptop with this stacktrace:
Fatal on LAPTOP-BGTGSTJU: Exception occurred in NLog
2018-01-28 11:39:33.1419 Fatal error occurred during execution of 'Worker #b261e15e' process. It will be stopped. See the exception for details.
| Exception occurred in NLog Void <Write>b__0(System.Exception)
at NLog.LoggerImpl.<>c__DisplayClass1.<Write>b__0(Exception ex)
at NLog.Internal.SingleCallContinuation.Function(Exception exception)
at NLog.Targets.MailTarget.ProcessSingleMailMessage(List`1 events)
at NLog.Targets.MailTarget.Write(AsyncLogEventInfo[] logEvents)
at NLog.Targets.MailTarget.Write(AsyncLogEventInfo logEvent)
at NLog.Targets.Target.WriteAsyncLogEvent(AsyncLogEventInfo logEvent)
at NLog.LoggerImpl.WriteToTargetWithFilterChain(TargetWithFilterChain targetListHead, LogEventInfo logEvent, AsyncContinuation onException)
at NLog.LoggerImpl.Write(Type loggerType, TargetWithFilterChain targets, LogEventInfo logEvent, LogFactory factory)
at NLog.Logger.WriteToTargets(LogLevel level, String message, Exception ex)
at CallSite.Target(Closure , CallSite , Object , String , Exception )
at System.Dynamic.UpdateDelegates.UpdateAndExecuteVoid3[T0,T1,T2](CallSite site, T0 arg0, T1 arg1, T2 arg2)
at Hangfire.Logging.LogProviders.NLogLogProvider.NLogLogger.LogException(LogLevel logLevel, Func`1 messageFunc, Exception exception)
at Hangfire.Logging.LogProviders.NLogLogProvider.NLogLogger.Log(LogLevel logLevel, Func`1 messageFunc, Exception exception)
at Hangfire.Logging.LoggerExecutionWrapper.Log(LogLevel logLevel, Func`1 messageFunc, Exception exception)
at Hangfire.Server.AutomaticRetryProcess.Execute(BackgroundProcessContext context)
at Hangfire.Server.ServerProcessExtensions.Execute(IServerProcess process, BackgroundProcessContext context)
at Hangfire.Server.InfiniteLoopProcess.Execute(BackgroundProcessContext context)
at Hangfire.Server.ServerProcessExtensions.Execute(IServerProcess process, BackgroundProcessContext context)
at Hangfire.Server.ServerProcessExtensions.RunProcess(IServerProcess process, BackgroundProcessContext context)
Can anyone help me to start understand what happen?
It looks like some job failed and it tried to retry … And it failed fatal then.
I looked at this resource with pointing that this could be Hangfire bug.

Related

Getting Error while running Integration Test for Web API core with swagger

I am getting below errors while executing my integration test for one of method to post the data in the dynamics crm. This is the first time i am writing integration test where my project is web api using to swagger and some of the azure resources like key vault, active directory.
While executing the Get call it seems to run fine all the steps are performed and getting results as well. But for Post call i can see the call is successful and database is inserted record for the latest call but while returning execustion point back to my integration test from my PostAsync method it fails in between.
Below is the error:
Message:
System.IO.IOException : The request was aborted or the pipeline has finished
Stack Trace:
ResponseStream.CheckNotComplete()
ResponseStream.WriteAsync(Byte[] buffer, Int32 offset, Int32 count, CancellationToken cancellationToken)
ErrorHandller.InvokeAsync(HttpContext context)
AuthenticationMiddleware.Invoke(HttpContext context)
StaticFileMiddleware.Invoke(HttpContext context)
SwaggerUIMiddleware.Invoke(HttpContext httpContext)
SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider)
CorrelationIdMiddleware.Invoke(HttpContext context, ICorrelationContextFactory correlationContextFactory)
<<SendAsync>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
ClientHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
HttpClient.FinishSendAsyncBuffered(Task`1 sendTask, HttpRequestMessage request, CancellationTokenSource cts, Boolean disposeCts)
GeoIntegrationTest.Test_AddState() line 72
--- End of stack trace from previous location where exception was thrown ---
and the code is as below
public async Task Test_AddState()
{
try
{
var data = new StateRequestModel
{
StateCode = "AL",
Name ="Alabama",
}
};
ByteArrayContent byteContent = BuildRequestObject(data);
var response = await httpClient.PostAsync("api/Geo/AddState", byteContent);
var result = response?.Content.ReadAsStringAsync().Result;
var addStateReposne = (ResponseModel<List<string>>) JsonConvert.DeserializeObject(result);
Assert.NotNull(result);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
}
catch (Exception ex)
{
throw;
}
}
Please help me to fix this issue and advice me if i can improve the code quality.
So, I got it resolved myself only. The problem was with the Timeout due to some long running process which was running more than default timeout of the HttpClient object.
client.Timeout = System.TimeSpan.FromMinutes(5);
Thanks everyone!!!

Using Unity with Windows Azure: An attempt was made to access a socket in a way forbidden by its access permissions

I am currently developing an ASP.NET MVC application that uses Unity for the IoC container. The solution is deployed to Windows Azure using a SQL Azure backend and implments Azure Caching.
After deploying the app to Windows Azure everything seems to work fine. But then after a few requests I get the error "An attempt was made to access a socket in a way forbidden by its access permissions".
For example, if I browse to the site and repeatedly initiate an AJAX POST (e.g. autocomplete input) request it will work fine for the first few requests, but then crash out (by means of displaying a HTTP 500 error in the Chrome Dev Tools console). Then if I try and fresh the page I get the sockets error until the app is restart or the pool is recycled.
Even if I flick between pages I get the same error after a while, i.e. it's not just isolated to the AJAX request. The AJAX request is just the quickest way to replicate the issue.
I'm wondering if the error An error occurred when trying to create a controller of type 'MySite.Web.MVC.Controllers.LocationsController'. Make sure that the controller has a parameterless public constructor.] in the stack trace is a red herring because the ILocationCacheService mapping used by the controller is being resolved by Unity. The AJAX request works for the first few times so it definitely resolves the mapping.
Everything works fine locally, or at least I can't replicate the error.
Stack Trace
Server Error in '/' Application.
An attempt was made to access a socket in a way forbidden by its access permissions
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Net.Sockets.SocketException: An attempt was made to access a socket in a way forbidden by its access permissions
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[SocketException (0x271d): An attempt was made to access a socket in a way forbidden by its access permissions]
System.Net.Sockets.Socket.DoMultipleAddressConnectCallback(Object result, MultipleAddressConnectAsyncResult context) +1847654
System.Net.Sockets.Socket.DoDnsCallback(IAsyncResult result, MultipleAddressConnectAsyncResult context) +34
System.Net.Sockets.Socket.BeginConnect(String host, Int32 port, AsyncCallback requestCallback, Object state) +271
Microsoft.ApplicationServer.Caching.SocketConnectionFactory.BeginConnect(String host, Int32 port, AsyncCallback callback, Object state, TimeSpan timeout) +469
Microsoft.ApplicationServer.Caching.TcpClientChannelFactory.BeginConnect(String host, Int32 port, AsyncCallback callback, Object state) +119
Microsoft.ApplicationServer.Caching.TcpClientChannel.ConnectAsync() +368
Microsoft.ApplicationServer.Caching.SocketClientChannel.TryGetTcpChannelUntilTimeout(TcpClientChannel clientChannel, ITcpChannel& chnl) +41
Microsoft.ApplicationServer.Caching.SocketClientChannel.Send(EndpointID endpoint, IVelocityRequestPacket packet) +188
Microsoft.ApplicationServer.Caching.SocketClientChannel.Send(EndpointID endpoint, ICreateMessage message) +112
Microsoft.ApplicationServer.Caching.SimpleSendReceiveModule.Send(EndpointID endpoint, RequestBody request, Int32 retries) +73
Microsoft.ApplicationServer.Caching.SimpleSendReceiveModule.SendMsgAndWait(EndpointID endpt, RequestBody reqMsg, TimeSpan requestTimeout, IRequestTracker& tracker) +428
Microsoft.ApplicationServer.Caching.SocketClientProtocol.SendMessage(EndpointID endPt, RequestBody request) +52
Microsoft.ApplicationServer.Caching.DataCacheFactory.EstablishConnection(IEnumerable`1 servers, RequestBody request, Func`3 sendMessageDelegate, DataCacheReadyRetryPolicy retryPolicy) +253
Microsoft.ApplicationServer.Caching.<>c__DisplayClass5.<Initialize>b__2(RequestBody req) +83
Microsoft.ApplicationServer.Caching.SocketClientProtocol.SendReceive(IVelocityRequestPacket request, Func`2 delegate, EndpointID& destination) +34
Microsoft.ApplicationServer.Caching.SocketClientProtocol.Initialize(IEnumerable`1 servers) +367
Microsoft.ApplicationServer.Caching.DataCacheFactory.GetCache(String cacheName, CreateNewCacheDelegate cacheCreationDelegate, DataCacheInitializationViaCopyDelegate initializeDelegate) +400
Microsoft.ApplicationServer.Caching.DataCacheFactory.GetCache(String cacheName) +61
Microsoft.ApplicationServer.Caching.DataCacheFactory.GetDefaultCache() +11
MySite.Services.Cache.Implementations.LocationCacheService..ctor(ILocationService locationService) +64
lambda_method(Closure , IBuilderContext ) +176
Microsoft.Practices.ObjectBuilder2.<>c__DisplayClass1.<GetBuildMethod>b__0(IBuilderContext context) +35
Microsoft.Practices.ObjectBuilder2.DynamicMethodBuildPlan.BuildUp(IBuilderContext context) +10
Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy.PreBuildUp(IBuilderContext context) +196
Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context) +193
Microsoft.Practices.ObjectBuilder2.BuilderContext.NewBuildUp(NamedTypeBuildKey newBuildKey) +113
Microsoft.Practices.Unity.ObjectBuilder.NamedTypeDependencyResolverPolicy.Resolve(IBuilderContext context) +48
lambda_method(Closure , IBuilderContext ) +107
Microsoft.Practices.ObjectBuilder2.<>c__DisplayClass1.<GetBuildMethod>b__0(IBuilderContext context) +35
Microsoft.Practices.ObjectBuilder2.DynamicMethodBuildPlan.BuildUp(IBuilderContext context) +10
Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy.PreBuildUp(IBuilderContext context) +196
Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context) +193
Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object existing, String name, IEnumerable`1 resolverOverrides) +165
[ResolutionFailedException: Resolution of the dependency failed, type = "MySite.Web.MVC.Controllers.LocationsController", name = "(none)".
Exception occurred while: Calling constructor MySite.Services.Cache.Implementations.LocationCacheService(MySite.Services.Interfaces.ILocationService locationService).
Exception is: SocketException - An attempt was made to access a socket in a way forbidden by its access permissions
-----------------------------------------------
At the time of the exception, the container was:
Resolving MySite.Web.MVC.Controllers.LocationsController,(none)
Resolving parameter "locationCacheService" of constructor MySite.Web.MVC.Controllers.LocationsController(MySite.Services.Cache.Interfaces.ILocationCacheService locationCacheService)
Resolving MySite.Services.Cache.Implementations.LocationCacheService,(none) (mapped from MySite.Services.Cache.Interfaces.ILocationCacheService, (none))
Calling constructor MySite.Services.Cache.Implementations.LocationCacheService(MySite.Services.Interfaces.ILocationService locationService)
]
Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object existing, String name, IEnumerable`1 resolverOverrides) +329
Microsoft.Practices.Unity.UnityContainer.Resolve(Type t, String name, ResolverOverride[] resolverOverrides) +15
Microsoft.Practices.Unity.UnityContainerExtensions.Resolve(IUnityContainer container, Type t, ResolverOverride[] overrides) +18
Unity.Mvc4.UnityDependencyResolver.GetService(Type serviceType) +67
System.Web.Mvc.DefaultControllerActivator.Create(RequestContext requestContext, Type controllerType) +41
[InvalidOperationException: An error occurred when trying to create a controller of type 'MySite.Web.MVC.Controllers.LocationsController'. Make sure that the controller has a parameterless public constructor.]
System.Web.Mvc.DefaultControllerActivator.Create(RequestContext requestContext, Type controllerType) +178
System.Web.Mvc.DefaultControllerFactory.GetControllerInstance(RequestContext requestContext, Type controllerType) +77
System.Web.Mvc.DefaultControllerFactory.CreateController(RequestContext requestContext, String controllerName) +66
System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase httpContext, IController& controller, IControllerFactory& factory) +191
System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state) +50
System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContext httpContext, AsyncCallback callback, Object state) +48
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData) +16
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +301
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155
I managed to resolve this issue using connection pooling for cache with maxconnectionstoserver="1". Here is the web.config setting for the datacacheclient section:
<dataCacheClient name="default" isCompressionEnabled="true" maxConnectionsToServer="1" connectionPool="true" useLegacyProtocol="false">

Illegal characters in path. while bundles javascript files

I am trying to bundlesup my javascrip files and css files to My MVC project. It is throwing exception while adding them.
Illegal characters in path.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentException: Illegal characters in path.
Source Error:
Line 9: public static void RegisterBundles(BundleCollection bundles)
Line 10: {
Line 11: bundles.Add(new ScriptBundle("~/bundles/jquery").Include("~/Scripts/jquery-{version}.js",
Line 12: "~/js/bootstrap.js",
Line 13: "~/js/jquery.flexslider-min.js",
"~/js/jquery.isotope.js",
"~/js/jquery.fancybox.pack.js?v=2.1.0",
"~/rs-plugin/js/jquery.themepunch.plugins.min.js",
"~/rs-plugin/js/jquery.themepunch.revolution.min.js",
"~/js/revolution.custom.js",
"~/js/custom.js"
));
Stack Trace:
[ArgumentException: Illegal characters in path.]
System.IO.Path.CheckInvalidPathChars(String path, Boolean checkAdditional) +10631190
System.Security.Permissions.FileIOPermission.CheckIllegalCharacters(String[] str) +30
System.Security.Permissions.FileIOPermission.AddPathList(FileIOPermissionAccess access, AccessControlActions control, String[] pathListOrig, Boolean checkForDuplicates, Boolean needFullPath, Boolean copyPathList) +97
System.Security.Permissions.FileIOPermission..ctor(FileIOPermissionAccess access, String path) +63
System.Web.InternalSecurityPermissions.PathDiscovery(String path) +29
System.Web.HttpRequest.MapPath(VirtualPath virtualPath, VirtualPath baseVirtualDir, Boolean allowCrossAppMapping) +149
System.Web.HttpServerUtility.MapPath(String path) +104
System.Web.Optimization.BundleTable.<get_MapPathMethod>b__0(String virtualPath) +67
System.Web.Optimization.ItemRegistry.Include(String[] virtualPaths) +644
System.Web.Optimization.Bundle.Include(String[] virtualPaths) +64
IntensifyTech.IntensifyTechConfig.RegisterBundles(BundleCollection bundles) in c:\Users\sxxx\SkyDrive\Trunk\IntensifyTech\IntensifyTech\App_Start\IntensifyTechConfig.cs:11
IntensifyTech.MvcApplication.Application_Start() in c:\Users\sxxxx\SkyDrive\Trunk\IntensifyTech\IntensifyTech\Global.asax.cs:24
[HttpException (0x80004005): Illegal characters in path.]
System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) +9859725
System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +118
System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +172
System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +336
System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +296
[HttpException (0x80004005): Illegal characters in path.]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9873912
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +254
Yep, its definitely this item: "~/js/jquery.fancybox.pack.js?v=2.1.0". This is a virtual path, not a url, so '?' characters are illegal in this context.

Umbraco / TeamCity BuildAgent nullReference error showing in Event Viewer

I'm noticing a strange error cropping up regularly with a site I've inherited the maintenance of from a former colleague.
Does it ring any bells for any of you out there?
It's an umbraco v 4.0.4.2 site, and TeamCity is most definitely NOT installed on this machine.
Here's the message:
Exception information:
Exception type: NullReferenceException
Exception message: Object reference not set to an instance of an object.
Request information:
Request URL: http://www.[[some website name]].co.uk/default.aspx
Request path: /default.aspx
User host address: [[some ip address]]
User:
Is authenticated: False
Authentication Type:
Thread account name: NT AUTHORITY\NETWORK SERVICE
Thread information:
Thread ID: 1
Thread account name: NT AUTHORITY\NETWORK SERVICE
Is impersonating: False
Stack trace:
at umbraco.requestHandler..ctor(XmlDocument _umbracoContent, String url) in d:\TeamCity\buildAgent\work\7380c184e9fcd3ea\umbraco\presentation\requestHandler.cs:line 230
at umbraco.UmbracoDefault.Page_PreInit(Object sender, EventArgs e) in d:\TeamCity\buildAgent\work\7380c184e9fcd3ea\umbraco\presentation\default.aspx.cs:line 113
at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)
at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
at System.EventHandler.Invoke(Object sender, EventArgs e)
at System.Web.UI.Page.OnPreInit(EventArgs e)
at System.Web.UI.Page.PerformPreInit()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
Custom event details:
For more information, see Help and Support Center at
The reference to Teamcity is just telling where the original file was compiled from in the filesystem.
It is most likely that you are missing a dll in the bin folder.

How to handle exception in Flush phase?

how can I handle exception that is thrown in NHibernate method Flush? I have a action for deleting objects. It loads the objects from repository using posted ids and calls repository.Delete(obj).
Leaving aside that my mapping in NHibernate is not complete and the delete results in "The DELETE statement conflicted with REFERENCE constraint" exception, this is good case to implement the exception hadling for this case.
So the exception is thrown in Flush and the Flush is called in UnitOfWorkPerRequestTask, which is task created and destroyed on every request and it starts and flushes the UnitOfWork (Rhino.Commons.UnitOfWork). This task is registered using Windsor container and LifestyleType.Transient and it is called by HttpApplication inside Begin and EndRequest methods.
Is there any way how to handle this exception in my delete action, so I can notice user that this object cannot be deleted because of some relationships?
The exception stack trace is here (not full):
NHibernate.Transaction.AdoTransaction.Commit() +212
Rhino.Commons.NHibernateTransactionAdapter.Commit() +33
Rhino.Commons.BaseUnitOfWorkFactory.TransactionalFlush(IsolationLevel isolationLevel) +116
Rhino.Commons.BaseUnitOfWorkFactory.TransactionalFlush() +35
Cereal.Mvc.DataModule.Tasks.UnitOfWorkPerRequestTask.DisposeCore() in C:\projects\Sample\Cereal.Mvc.DataModule\Tasks\UnitOfWorkPerRequestTask.cs:33
System.Web.Mvc.Extensibility.Disposable.Dispose(Boolean disposing) in C:\projects\System.Web.Mvc.Extensibility\Abstraction\Disposable.cs:52
System.Web.Mvc.Extensibility.Disposable.Dispose() in C:\projects\System.Web.Mvc.Extensibility\Abstraction\Disposable.cs:35
Castle.MicroKernel.LifecycleConcerns.DisposalConcern.Apply(ComponentModel model, Object component) +47
Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.ApplyConcerns(Object[] steps, Object instance) +129
Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.ApplyDecommissionConcerns(Object instance) +106
Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.InternalDestroy(Object instance) +37
Castle.MicroKernel.ComponentActivator.AbstractComponentActivator.Destroy(Object instance) +37
Castle.MicroKernel.Lifestyle.AbstractLifestyleManager.Release(Object instance) +48
Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleManager.Evict(Object instance) +38
Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule.Application_EndRequest(Object sender, EventArgs e) +305
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +68
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75
Thanks for help.
If you call Flush() in a UnitOfWork, you can only catch the error and log it.
If you want your users inform about the error, then close the transaction or do the Flush earlierer (as stated in the comments of Paco and cbp). One place is to handle it in your action method. Check the outcome and report it to the user with an error page.

Resources