You are viewing limited content. For full access, please sign in.

Question

Question

Long-running processes which access Laserfiche eventually fail

SDK
asked on May 3, 2017 Show version history

(Note: I have a few options for work-arounds for this issue, but I'm looking for an answer to this specific problem. Feel free to suggest work-arounds, but I may not accept those as answers.)

I'm using SDK 10 for C# to import files into Laserfiche, attaching metadata and updating that metadata periodically. I have selected a method of queuing updates to Laserfiche, executing them on a single, long-running background thread in the context of a web application (IIS).

The problem I'm having is that Laserfiche eventually stops allowing log-ins with the following error, which is from the framework exception:

    Invalid token for impersonation - it cannot be duplicated.

After researching online, I understand this error to be related to identity tokens associated with HTTP connections. Unfortunately, this is nothing I can affect directly from my end, and I'm not aware of how to configure Laserfiche to properly handle this situation. I've tried changing the lifecycle of various objects. It seems that, even with a new session and new repository registration, I cannot get any Laserfiche interaction to occur until I dispose of the background thread and start a new one. I suspect that possibly the credentials are being stored in a thread-static way.

I get this error regardless of login style. Using .LogIn(registration) and .LogIn(username, password, registration) both cause the problem (I have a LF user associated with an AD user).

 

link to details about this exception (http://stackoverflow.com/questions/8993293/windowsidentity-impersonate-in-asp-net-randomly-invalid-token-for-impersonation)

 

I don't want to doubt the Laserfiche SDK and developers, but is a bug in how Laserfiche handles its sessions and HTTP communication when executing multiple requests on a single, long-running thread? Is there a known work-around that won't require me to change my threading model?

0 0

Answer

SELECTED ANSWER
replied on May 10, 2017

My current solution to this problem is not to attempt to synchronize Laserfiche SDK calls to a single background thread, but instead to synchronize with a mutex from the individual request threads, which is obviously a performance bottleneck, but acceptable for my application in its current state.

0 0

Replies

replied on May 4, 2017

What is the call stack for that exception?

0 0
replied on May 9, 2017 Show version history

(SDK assembly version is 9.2.0.0)

 

This is the part of the call stack which is relevant to Laserfiche. I've removed the upper frames which only relate to my code. I have the same problem when using the session constructor which includes username and password, as well as implicitly with AD (same user, mapped).

 

[ArgumentException: Invalid token for impersonation - it cannot be duplicated.][TargetInvocationException: Exception has been thrown by the target of an invocation.] System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) +153 System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) +336 System.AppDomain.get_Id() +0 <CrtImplementationDetails>.DoCallBackInDefaultDomain(IntPtr function, Void* cookie) +224 <CrtImplementationDetails>.LanguageSupport.InitializeDefaultAppDomain(LanguageSupport* ) +27 <CrtImplementationDetails>.LanguageSupport.Initialize(LanguageSupport* ) +316 <CrtImplementationDetails>.LanguageSupport.Initialize(LanguageSupport* ) +90 [ModuleLoadException: The C++ module failed to load while attempting to initialize the default appdomain. ] <CrtImplementationDetails>.LanguageSupport.Initialize(LanguageSupport* ) +170 .cctor() +28 [TypeInitializationException: The type initializer for '<Module>' threw an exception.] Laserfiche.RepositoryAccess.SessionLocale..ctor(Session session, Boolean useUserOverride) +0 Laserfiche.RepositoryAccess.Session.LoginToServer(RepositoryRegistration repository, HttpCredential credentials) +272 Laserfiche.RepositoryAccess.Session.LogIn(String userName, String password, RepositoryRegistration repository) +196 

0 0
replied on May 9, 2017

I don't fully understand what is failing here.  It looks like .Net is trying to run some module initialization in the default app domain.  There are some suggestions that you can change the configuration, but this might not be applicable to an ASP.Net scenario.  This post talks about changing the settings for the app pool.

Another possibility would be to upgrade to a newer version of the SDK.  The C++ portions have been re-implemented in managed code, and this might avoid this particular problem.

0 0
replied on May 10, 2017

Brian, I believe you are focusing on a more general error message, the specific problem relates to impersonation tokens. My code doesn't touch AppDomains, has no C++ code, and does no serialization (marshaling is mentioned in the call stack.)

At any rate, even if this were an SDK bug, I wouldn't be able to benefit from a fix being that I'm on 9.2, so at this point I don't really care if this problem gets solved, so I'll close the issue.

If any other user ever comes up with this problem, perhaps you can refer back to this message to help you troubleshoot it.

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.