This project has moved. For the latest updates, please go here.
1

Closed

System.AccessViolationException

description

I am trying to run my application in a docker container, but it crashes with the following error:
Unhandled Exception: System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
   at std._Func_class<void>.()(_Func_class<void>* )
   at Microsoft.ClearScript.V8.NativeCallbackImpl.Invoke()
   at Microsoft.ClearScript.Util.MiscHelpers.Try(Action action)
   at Microsoft.ClearScript.Util.NativeCallbackTimer.OnTimer(Object state)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.TimerQueueTimer.CallCallback()
   at System.Threading.TimerQueueTimer.Fire()
   at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
   at System.Threading.ThreadPoolWorkQueue.Dispatch()
another exception
Unhandled Exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
   at V8Context.Create(SharedPtr<V8Isolate>* , StdString* , Boolean , Boolean , Int32 )
   at Microsoft.ClearScript.V8.V8ContextProxyImpl..ctor(V8IsolateProxy gcIsolateProxy, String gcName, Boolean enableDebugging, Boolean disableGlobalMembers, Int32 debugPort)
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
   at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, StackCrawlMark& stackMark)
   at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
   at System.Activator.CreateInstance(Type type, Object[] args)
   at Microsoft.ClearScript.V8.V8Proxy.CreateImpl[T](Object[] args)
   at Microsoft.ClearScript.V8.V8ScriptEngine..ctor(V8Runtime runtime, String name, V8RuntimeConstraints constraints, V8ScriptEngineFlags flags, Int32 debugPort)
   at JavaScriptEngineSwitcher.V8.V8JsEngine..ctor(V8Settings settings)
   at JavaScriptEngineSwitcher.V8.V8JsEngineFactory.CreateEngine()
   at React.JavaScriptEngineFactory.GetFactory(JsEngineSwitcher jsEngineSwitcher, Boolean allowMsie)
   at React.JavaScriptEngineFactory..ctor(JsEngineSwitcher jsEngineSwitcher, IReactSiteConfiguration config, IFileSystem fileSystem)
   at lambda_method(Closure , Object[] )
   at React.TinyIoC.TinyIoCContainer.ConstructType(Type requestedType, Type implementationType, ConstructorInfo constructor, NamedParameterOverloads parameters, ResolveOptions options)
   at React.TinyIoC.TinyIoCContainer.SingletonFactory.GetObject(Type requestedType, TinyIoCContainer container, NamedParameterOverloads parameters, ResolveOptions options)
   at React.TinyIoC.TinyIoCContainer.ResolveInternal(TypeRegistration registration, NamedParameterOverloads parameters, ResolveOptions options)
   at React.TinyIoC.TinyIoCContainer.ConstructType(Type requestedType, Type implementationType, ConstructorInfo constructor, NamedParameterOverloads parameters, ResolveOptions options)
   at React.TinyIoC.TinyIoCContainer.CustomObjectLifetimeFactory.GetObject(Type requestedType, TinyIoCContainer container, NamedParameterOverloads parameters, ResolveOptions options)
   at React.TinyIoC.TinyIoCContainer.ResolveInternal(TypeRegistration registration, NamedParameterOverloads parameters, ResolveOptions options)
   at React.TinyIoC.TinyIoCContainer.Resolve[ResolveType]()
   at React.AspNet.HtmlHelperExtensions.get_Environment()
   at React.AspNet.HtmlHelperExtensions.React[T](IHtmlHelper htmlHelper, String componentName, T props, String htmlTag, String containerId, Boolean clientOnly, Boolean serverOnly, String containerClass)
   at AspNetCore._Views_Site_Menu_cshtml.<ExecuteAsync>d__33.MoveNext() in /Views/Site/Menu.cshtml:line 3
   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder.Start[TStateMachine](TStateMachine& stateMachine)
   at AspNetCore._Views_Site_Menu_cshtml.ExecuteAsync()
There are a lot of script code in the application, so it is difficult to find the specific lines of code that causes the crash. Does anyone have any ideas what could cause that or advice how to debug this issue?
Closed Apr 18 at 8:54 PM by ClearScript

comments

ClearScript wrote Apr 16 at 7:53 PM

Hello!

These stacks (especially the second one) almost always indicate out-of-memory conditions, which V8 handles by crashing immediately via unrecoverable access violation.

Ignoring the possibility of runaway script code, this can happen if you create a large number of V8 runtimes in a 32-bit process. Each V8 runtime reserves a large block of address space at startup, and in a 32-bit process you can run out of address space with just a few dozen instances.

Another possibility is that the V8 runtime is too constrained to complete startup. Are you using V8RuntimeConstraints to specify memory usage limits?

Also, could it be that Docker is imposing various limits on your application?

Thanks!

andreymir wrote Apr 18 at 8:47 PM

Thanks! You are right, it was a memory limit issue. I think Docker has some default memory constraint for the container. After I specified 2GB memory for the container the application runs fine.

ClearScript wrote Apr 18 at 8:53 PM

That's great to hear! Thanks for following up.