The EntitySpaces Community

Share and learn about the EntitySpaces Architecture.
Welcome to The EntitySpaces Community Sign in | Join | Help
in
Home Forums Photos

cached connections in ES (or the Connector, hard to know)

Last post 11-05-2007, 5:48 AM by websight. 11 replies.
Sort Posts: Previous Next
  •  08-29-2007, 1:31 PM 4878

    cached connections in ES (or the Connector, hard to know)

    I've mentioned this very irritating problem before, but now I have some better clues and I think the cause.

    If you have an application open that uses ES to work with MySql, then... for any reason MySql is restarted and you try to use your application you will get a terminated connection exception (or something like that)

    It's very easy to reproduce:

    1. Create a simple winforms app
    2. add a button to load a collection of entities
    3. Click the button to load entities (yay, it works)
    4. restart MySql
    5. Click that button again = exception!

    The only thing I can do on me end is wrap EVERY call that will result in a DB hit in a try/catch and try again.  yuck, very ugly.  However the ES guys could probably handle this by retrying the connection in just a few methods in the Core stuff.  Am I wrong?

    I'm not saying this is an ES problem, but it could be solved by ES much easier than an end user (like me) can.

    Can you guys verify if you can reproduce this bug on your end?  If so, can we consider a fix?  Please?

    -Steve 

  •  08-29-2007, 1:42 PM 4879 in reply to 4878

    Re: cached connections in ES (or the Connector, hard to know)

    It's probably a bug in the MySQL provider, there's no way this is a bug in ES, we simply open and close every connection. Most likely these connections are laying around in the connection pool managed by .NET and when you restart MySQL one of those connections is later yanked from the pool and tries to access the old instance of MySQL. I would search on the MySQL forums, we can take a look too. I wonder if you stopped the SQL Server service if the same thing would happen?  We cannot adjust the core for this kind of thing however. Let's both check the MySQL forums and see what we find out. Why don't you post the complete call stack ....

    ES doesn't cache connections, there is a connection pool built into .NET and ADO.NET data providers take advantage of it ...
    http://www.ondotnet.com/pub/a/dotnet/2004/02/09/connpool.html

     

     


    EntitySpaces | Twitter | BLOG | Please honor our Software License
  •  08-29-2007, 2:33 PM 4881 in reply to 4879

    Re: cached connections in ES (or the Connector, hard to know)

    I agree, I don't think it's an ES thing really.  I can't get the full stack until people leave for the day (they are using the system and we have only one server) but I will do this later and post the results.  I will hit the forums as well and see what I can find.
  •  08-29-2007, 2:44 PM 4882 in reply to 4881

    Re: cached connections in ES (or the Connector, hard to know)

    I really want to get this solved, so I kicked everyone off!

     

    here is the stack trace:

       at EntitySpaces.Interfaces.esDataProvider.esLoadDataTable(esDataRequest request, esProviderSignature sig)
       at EntitySpaces.Interfaces.esDynamicQuery.Load()
       at EntitySpaces.Core.esEntityCollection.LoadAll()
       at PMD.ManufacturingStudio.ProductionBuildModule.Services.BuildOrderService.GetBuildOrders(Boolean skipCache) in C:\PMDRepository\Tools\ManufacturingStudio\Source\Modules\ProductionBuildModule\trunk\Services\BuilOrderService.cs:line 196
       at PMD.ManufacturingStudio.ProductionBuildModule.BuildOrdersViewPresenter.UpdateBuildOrders() in C:\PMDRepository\Tools\ManufacturingStudio\Source\Modules\ProductionBuildModule\trunk\Views\BuildOrdersView\BuildOrdersViewPresenter.cs:line 299
       at PMD.ManufacturingStudio.ProductionBuildModule.BuildOrdersViewPresenter.RefreshBuildOrderList() in C:\PMDRepository\Tools\ManufacturingStudio\Source\Modules\ProductionBuildModule\trunk\Views\BuildOrdersView\BuildOrdersViewPresenter.cs:line 93
       at PMD.ManufacturingStudio.ProductionBuildModule.BuildOrdersView.toolStripButton_RefreshList_Click(Object sender, EventArgs e) in C:\PMDRepository\Tools\ManufacturingStudio\Source\Modules\ProductionBuildModule\trunk\Views\BuildOrdersView\BuildOrdersView.cs:line 304
       at System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e)
       at System.Windows.Forms.ToolStripButton.OnClick(EventArgs e)
       at System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e)
       at System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e)
       at System.Windows.Forms.ToolStripItem.FireEventInteractive(EventArgs e, ToolStripItemEventType met)
       at System.Windows.Forms.ToolStripItem.FireEvent(EventArgs e, ToolStripItemEventType met)
       at System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea)
       at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
       at System.Windows.Forms.ToolStrip.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.Run(Form mainForm)
       at Microsoft.Practices.CompositeUI.WinForms.FormShellApplication`2.Start() in C:\Program Files\Microsoft Composite UI App Block\CSharp\Source\CompositeUI.WinForms\FormShellApplication.cs:line 31
       at PMD.ManufacturingStudio.Infrastructure.Shell.ShellApplication.Start() in C:\PMDRepository\Tools\ManufacturingStudio\Source\Infrastructure\Shell\trunk\ShellApplication.cs:line 152
       at Microsoft.Practices.CompositeUI.CabApplication`1.Run() in C:\Program Files\Microsoft Composite UI App Block\CSharp\Source\CompositeUI\CabApplication.cs:line 81
       at PMD.ManufacturingStudio.Infrastructure.Shell.ShellApplication.RunInDebugMode() in C:\PMDRepository\Tools\ManufacturingStudio\Source\Infrastructure\Shell\trunk\ShellApplication.cs:line 169
       at PMD.ManufacturingStudio.Infrastructure.Shell.ShellApplication.Main() in C:\PMDRepository\Tools\ManufacturingStudio\Source\Infrastructure\Shell\trunk\ShellApplication.cs:line 82
       at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
       at System.Runtime.Hosting.ManifestRunner.Run(Boolean checkAptModel)
       at System.Runtime.Hosting.ManifestRunner.ExecuteAsAssembly()
       at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext, String[] activationCustomData)
       at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssemblyDebugInZone()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()

    Gonna do some experimenting and post back when I'm done 

  •  08-29-2007, 2:47 PM 4883 in reply to 4882

    Re: cached connections in ES (or the Connector, hard to know)

    Found a solution, although I'm not nuts about it.

    connectionString="Server=192.168.1.100;Pooling=false;Database=pmd_manf2_test;Uid=xxxxxxx;Pwd=xxxxxxx" 

  •  08-29-2007, 4:06 PM 4884 in reply to 4883

    Re: cached connections in ES (or the Connector, hard to know)

    Wow, that's drastic, I would never take that action. I'd make a global handler for any unhandled exceptions and put a message up to the user. Turning connection pooling off can significantly degrade the performance of your application for the off hand chance the the service restarting, besides, both Windows.Forms and ASP.NET have global error handling mechanisms that would allow you to put code in to handle this.

    EntitySpaces | Twitter | BLOG | Please honor our Software License
  •  08-29-2007, 11:20 PM 4887 in reply to 4884

    Re: cached connections in ES (or the Connector, hard to know)

    Mike.Griffin:
    Wow, that's drastic, I would never take that action. I'd make a global handler for any unhandled exceptions and put a message up to the user. Turning connection pooling off can significantly degrade the performance of your application for the off hand chance the the service restarting, besides, both Windows.Forms and ASP.NET have global error handling mechanisms that would allow you to put code in to handle this.

    I can see why you would think it was drastic.  My application has at most, 4 concurrent users.  I did some quick performance testing and only the first db trip after a server restart is slow, so there still appears to be some caching happening somewhere, that or ES is leaving the connection open?  I don't know.  I have exception handling in place to handle the error and let the user know, I haven't spent time investigating how to recover and solve the issue without an application restart.  It seems that simply hitting the DB over and over doesn't clear the invalid cached connection.  I'm not proposing my particular solution as the best solution or even a good one, just a solution that works around the problem.  If you know of a way to not only handle the error (which I'm doing) but correct the condition causing it I would really appreciate any info.  I will think about it as well and post any additional ideas or information I can find.

    -Steve 

  •  08-30-2007, 4:47 AM 4892 in reply to 4887

    Re: cached connections in ES (or the Connector, hard to know)

    I think you've done all you can do at this point. There is no way ES is leaving connections open nor do we do any caching. If it were my app I'd leave connection pooling on, catch the error globally and ask the user to restart the application. There is nothing EntitySpaces can do for this situation as it's a higher level issue.

    EntitySpaces | Twitter | BLOG | Please honor our Software License
  •  08-30-2007, 4:59 AM 4893 in reply to 4892

    Re: cached connections in ES (or the Connector, hard to know)

    I tried to re-create this on my dev machine, but cannot. I started my test app and clicked the button for a Query.Load. I stopped and re-started MySQL and clicked the button again, and everything was fine. I tried this under both IIS and Apache. Starting and stopping MySQL seemed to have no affect on the app at all, as long as I did not try something when MySQL was stopped.
    David Neal Parsons
    www.entityspaces.net
  •  08-30-2007, 6:50 AM 4905 in reply to 4893

    Re: cached connections in ES (or the Connector, hard to know)

    Maybe it's a difference between a web app and winforms?
  •  08-30-2007, 4:09 PM 4931 in reply to 4893

    Re: cached connections in ES (or the Connector, hard to know)

    My test app is a winform app with a button for LoadAll and 2 buttons for comparing 2 Query.Loads. MySQL connects via TCP/IP using sockets, so I must have either IIS or Apache running on the machine to connect. The connection string contains localhost as the data source.

    I'm curious why MySQL is restarting so often that this is an issue. Is it possible that it is not shutting down correctly before the restart, and leaving some old connections in the pool? In my case, MySQL is not running as a service. I shut it down with

    mysql\bin\mysqladmin --user=pma --password= shutdown.

    And, restart it with

    mysql\bin\mysqld --defaults-file=mysql\bin\my.cnf --standalone --console.


    David Neal Parsons
    www.entityspaces.net
  •  11-05-2007, 5:48 AM 6345 in reply to 4931

    Re: cached connections in ES (or the Connector, hard to know)

    Put this in your connection string :

    Connection Reset=true;

    It should resolve your problem.

View as RSS news feed in XML