Error disposing contextregistry contents / closing httpsession / clearing session cache - asp.net

I encounter a fatal crush of an asp.net application when i run the app the second time. The first time after a re-build runs successfully, but the second run (without a new rebuild) fails. After a new re-build the app runs again but the second run without a new rebuild fails etc. So i have to rebuild each time for an app run to be successful.
Error: Cannot resolve type [BiFiModelSweden.BiFiModelSwedenClass] for object with name 'BiFiModelSweden' defined in file [C:...\bin\BiFiContext.xml] line 8
This occurs at the last command below while creating the IApplicationContext which is null:
String cx1 = ConfigurationManager.AppSettings["cx1"];
String cx2 = ConfigurationManager.AppSettings["cx2"];
IApplicationContext cxt = new XmlApplicationContext(HttpContext.Current.Request. MapPath(cx1), HttpContext.Current.Request.MapPath(cx2));
After profiling the development webserver running the application, using ANTS memory profiler, we get an output:
Not all objects were deleted from the contextregistry. Did you forget to use base.Dispose()?
We've then tried all we can to use the dispose method using all sorts of ways. We cannot get to overcome this fatal crash of the application!
extra observation: log4net keeps logging even if the application is stopped mid-way. Does this symbolise a zombie session? could this be the problem, that we never kill one session completely when we start a new applicaiton run/session? leading to the fatal exception? that the previous session is left hanging and holding on (locking) to resources?
if this is the case, we've tried all ways of killing the session:
* session.Abandon()
* gc.finalize()
* etc
nothing works. The only workaround is manual deletion of the cache...which is impractical. How do we solve this!!

Related

SQLite.NET PCL Busy Exception

We are using the SQLite.NET PCL in a Xamarin application.
When putting the database under pressure by doing inserts into multiple tables we are seeing BUSY exceptions being thrown.
Can anyone explain what the difference is between BUSY and LOCKED? And what causes the database to be BUSY?
Our code uses a single connection to the database created using the following code:
var connectionString = new SQLiteConnectionString(GetDefaultConnectionString(),
_databaseConfiguration.StoreTimeAsTicks);
var connectionWithLock = new SQLiteConnectionWithLock(new SQLitePlatformAndroid(), connectionString);
return new SQLiteAsyncConnection (() => { return connectionWithLock; });
So our problem turned out to be that although we had ensured within the class we'd written that it only created a single connection to the database we hadn't ensured that this class was a singleton, therefore we were still creating multiple connections to the database. Once we ensured it was a singleton then the busy errors stopped
What I've take from this is:
Locked means you have multiple threads trying to access the database, the code is inherently not thread safe.
Busy means you have a thread waiting on another thread to complete, your code is thread safe but you are seeing contention in using the database.
...current operation cannot proceed because the required resources are locked...
I am assuming that you are using async-style inserts and are on different threads and thus an insert is timing out waiting for the lock of a different insert to complete. You can use synchronous inserts to avoid this condition. I personally avoid this, when needed, by creating a FIFO queue and consuming that queue synchronously on a dedicated thread. You could also handle the condition by retrying your transaction X number of times before letting the Exception ripple up.
SQLiteBusyException is a special exception that is thrown whenever SQLite returns SQLITE_BUSY or SQLITE_IOERR_BLOCKED error code. These codes mean that the current operation cannot proceed because the required resources are locked.
When a timeout is set via SQLiteConnection.setBusyTimeout(long), SQLite will attempt to get the lock during the specified timeout before returning this error.
Ref: http://www.sqlite.org/lockingv3.html
Ref: http://sqlite.org/capi3ref.html#sqlite3_busy_timeout
I have applied the following solution which works in my case(mobile app).
Use sqlitepclraw.bundle_green nugget package with SqlitePCL.
Try to use the single connection throughout the app.
After creating the SQLiteConnection.
Apply busytime out using following call.
var connection = new SQLiteConnection(databasePath: path);
SQLite3.BusyTimeout(connection.Handle, 5000); // 5000 millisecond.

Workflow hosted inside WorkflowApplication, aborting on persistence

I have been trying to resolve a somewhat intermittent issue working with a long running state machine running inside a WorkflowApplication. I can step through the workflow and this behaves as expected, transitioning through the states as expected, then a bookmark is reached which then persists the workflow. However, the workflow is then aborted and I get the following message:
The execution of an InstancePersistenceCommand was interrupted because the instance owner registration for owner ID 'ba26f4e9-f38b-4179-aa09-31ab9f8af337' has become invalid. This error indicates that the in-memory copy of all instances locked by this owner have become stale and should be discarded, along with the InstanceHandles. Typically, this error is best handled by restarting the host.
The Sql Instance store is initialised as follows:
SqlStore = new SqlWorkflowInstanceStore(ConfigurationManager.ConnectionStrings["SqlInstanceStore"].ConnectionString);
SqlStore.HostLockRenewalPeriod = TimeSpan.FromSeconds(15);
SqlStore.InstanceCompletionAction = InstanceCompletionAction.DeleteAll;
handle = SqlStore.CreateInstanceHandle();
InstanceView sqlView = SqlStore.Execute(handle, new CreateWorkflowOwnerCommand(), TimeSpan.FromSeconds(30));
SqlStore.DefaultInstanceOwner = sqlView.InstanceOwner;
WorkflowHost = new WorkflowApplication(WorkflowDefinition, inputs);
WorkflowHost.Run();
To create the bookmark:
context.CreateBookmark(bkmk, OnResume);
The exception doesn't really provide enough information to help troubleshooting this issue. Any help would be appreciated.
I managed to resolve this by using an overload of the instance store where I am now passing a new GUID. Need to understand this a bit more.
handle = SqlStore.CreateInstanceHandle(Guid.NewGuid());

Issue running ASPX page using Scheduled Task

I have a scheduled task set up to run Scan.aspx every 3 minutes in IE7. Scan.aspx reads data from 10 files in sequence. These files are constantly being updated. The values from the file are inserted into a database.
Sporadically, the value being read is truncated or distorted. For example, if the value in the file was "Hello World", random entries such as "Hello W", "Hel", etc. will be in the database. The timestamps on these entries appear completely random. Sometimes at 1:00 am, sometimes at 3:30 am. And some nights, this doesn't occur at all.
I'm unable to reproduce this issue when I debug the code. So I know under "normal" circumstances, the code executes correctly.
UPDATE:
Here is the aspx codebehind (in Page_Load) to read a text file (this is called for each of the 10 text files):
Dim filename As String = location
If File.Exists(filename) Then
Using MyParser As New FileIO.TextFieldParser(filename)
MyParser.TextFieldType = FileIO.FieldType.Delimited
MyParser.SetDelimiters("~")
Dim currentrow As String()
Dim valueA, valueB As String
While Not MyParser.EndOfData
Try
currentrow = MyParser.ReadFields()
valueA= currentrow(0).ToUpper
valueB = currentrow(1).ToUpper
//insert values as record into DB if does not exist already
Catch ex As Exception
End Try
End While
End Using
End If
Any ideas why this might cause issues when running multiple times throughout the day (via scheduled task)?
First implement a Logger such as Log4Net in your ASP.NET solution and Log method entry and exit points in your Scan.aspx as well as your method for updating the DB. There is a chance this may provide some hint of what is going on. You should also check the System Event Log to see if any other event is associated with your failed DB entries.
ASP.NET is not the best thing for this scenario especially when paired with a Windows scheduled task; this is not a robust design. A more robust system would run on a timer inside a Windows-Service-Application. Your code for reading the files and updating to the DB could be ported across. If you have access to the server and can install a Windows Service, make sure you also add Logging to the Windows Service too!
Make sure you read the How to Debug below
Windows Service Applications intro on MSDN: has further links to:
How to: Create Windows Services
How to: Install and Uninstall Services
How to: Start Services
How to: Debug Windows Service Applications]
Walkthrough: Creating a Windows Service
Application in the Component Designer
How to: Add Installers to Your Service Application
Regarding your follow up comment about the apparent random entries that sometimes occur at 1am and 3.30am: you should:
Investigate the IIS Log for the site when these occur and find out what hit(visited) the page at that time.
Check if there is an indexing service on the server which is visiting your aspx page.
Check if Anti-Virus software is installed and ascertain if this is visiting your aspx page or impacting the Asp.Net cache; this can cause compilation issues such as file-locks on the aspnet page in the aspnet cache; (a scenario for aspnet websites as opposed to aspnet web applications) which could give weird behavior.
Find out if the truncated entries coincide with the time that the files are updated: cross reference your db entries timestamp or logger timestamp with the time the files are updated.
Update your logger to log the entire contents of the file being read to verify you've not got a 'junk-in > junk-out' scenario. Be careful with diskspace on the server by running this for one night.
Find out when the App-Pool that your web app runs under is recycled and cross reference this with the time of your truncated entries; you can do this with web.config only via ASP.NET Health Monitoring.
Your code is written with a 'try catch' that will bury errors. If you are not going to do something useful with your caught error then do not catch it. Handle your edge cases in code, not a try catch.
See this try-catch question on this site.

Error when running TcmReindex.exe

I am currently trying to get search working in my Tridion 2011 installation. I read in another article that I should run the TcmReIndex.exe tool in the Tridion/bin folder to re-index all my sites. So I tried this and it failed with a message box giving the following details
Unable to get list of Publication items.
Unable to Intialize TDSE object.
The wait operation timed out
Connection Timeout Expired. The timeout period elapsed while attempting to consume the pre-login handshake acknowledgement. This could be because the pre-login handshake failed or the server was unable to respond back in time. The duration spent while attempting to connect to this server was - [Pre-Login] initialization=21054; handshake=35;
The wait operation timed out
A database error occurred while executing Stored Procedure "EDA_TRUSTEES_GETTRUSTEEETOKEN"
I have four fairly large publications (100 000+ items in total) which I am trying to index.
Any ideas?
Whenever I get "Unable to Intialize TDSE object." errors, I typically write a small test script using VBScript, and try running it on the CMS server. Whilst this does not directly solve the problem, it often gives some insight into the issue by logging information in the event viewer. Try creating a test.vbs file as follows and running it:
Set tdse = CreateObject("TDS.TDSE")
tdse.initialize()
msgbox(tdse.User.Description)
Set tdse = Nothing
If it throws any errors, please let me know, and it may help us solve the problem. If it gives you a popup with your user description, then I am completely barking up the wrong tree.
I haven't come to anything conclusive but it seems like my issue may have been a temporary one as it just started working. I did increase all timeouts in Tridion MMC > Timeout Settings by 100 times their amounts but I suspect that this wasn't the issue, when it works the connection is almost instant.
If anyone else has this issue
Restart the computer the content manager is installed on, try again.
Wait an hour or two, try again.
Increase timeouts, try again.
I've run the process a few more times and it seems to be working correctly.

IIS7/Win7 - App Pool is failing suddenly

After nearly 5 months with this configuration I am now getting a series of:
"A process serving application pool 'Classic .NET AppPool' suffered a fatal communication error with the Windows Process Activation Service. The process id was '1640'."
This leads to:
Application pool 'Classic .NET AppPool' is being automatically disabled due to a series of failures in the process(es) serving that application pool.
I cannot, for the life of me, figure out what changed to start causing this nor can I figure out how to possibly dig in deeper to find out what is causing it to fail.
I recently (2 weeks ago) started adding Entity Frameworks to my solution. Right before this happened I did get an "out of stack space" error due to a reported self-referenced call. I cannot find any calls like that in the code I wrote and am suspecting EF may have added a join in my simple (3 table) model that is wrong.
Any ideas on where to start looking? What would cause the AppPool to fail?
TIA
NOTE:
An unhandled exception of type 'System.StackOverflowException' occurred in mscorlib.dll
I have an outside object that calls this method to get a single record:
public static AutoNegotiationDetails GetAutoNegotiationByCompany(Guid companyId)
{
return RivWorks.Controller.Negotiation.GetAutoNegotiationByCompany(companyId);
}
That method calls into:
internal static AutoNegotiationDetails GetAutoNegotiationByCompany(Guid companyId)
{
var autoNeg = from a in _dbRiv.AutoNegotiationDetails where a.CompanyId == companyId select a;
var ret = autoNeg.FirstOrDefault();
return ret;
}
In stepping through it I can set a break point inside the first method, step into the second method, see the record populated, return to the first method then finally exit the method. At that point my IDE locks up for a few seconds until I get the StackOverflow error.
For a more accurate picture of the whole system:
Running WebOrb30 on the IIS machine.
In the VS IDE -> Attach to Process (INETINFO.exe)
Log into WebOrb30 -> Management Console -> Drill down to service entry point -> Enter CompanyID into input box -> Click Invoke
Hit break point in VS IDE -> (See above)
NOTE:
Looks like it may be caused by another issue in EF. See C# - Entity Framework - An unhandled exception of type 'System.StackOverflowException' occurred in mscorlib.dll for further clarification.
I may be that you have two apps/sites using one app pool, but the apps/sites are running different .net versions.
This might not be the case, but its the only similar recurring problem i've ever had with iis.
Because of a bug in my Entity Framework I was getting a cyclic call into one of my relationships. This was causing a stack overflow which was reported to WebOrb as a general error and WebOrb would halt causing the App Pool to crash. (I still don't quite understand all the specifics). When I rebuilt my EF Model without the relationships the behavior went away. (sigh/)
EF will be another question (or series of questions).

Resources