Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Remoting / July 2004

Tip: Looking for answers? Try searching our database.

LifetimeServices is killing me.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Bob Rundle - 28 Jul 2004 21:36 GMT
LifetimeServices seems to be killing off my SAO's and I am getting very
frustrated.

I've overridden MBR:InitializeLifetimeService() to return null for all of my
objects, but this does not solve it.

I've tried writing a test problem, per the requirements of this group, and
the test program works fine.  The client part of the test program can sleep
for 20 min between accesses of the remote object and everything is fine.

I suspect the problem is not the root SAO that I am marshalling, but with a
child object that the client attaches to through the root object.

The first access to the remote child object works fine.  If I keep accessing
the child object everything is fine.  Now...if I let the client sit idle for
5 minutes and then try to access the child object then I get the error
"Requested Service not found", which in my experience means that your object
has been whacked by Lifetime Mafia.

I would appreciate any ideas on how to get to the bottom of this problem.

Regards,
Bob Rundle
Sunny - 28 Jul 2004 21:59 GMT
Hi Bob,

every object exposed to remoting depends on the LifetimeServices. So,
you need to assure that the child object is also well maintained. If it
is CAO, the best approach will be to use client side sponsors, so when
the client is done with it and disconnects, this object will die.

Sunny

> LifetimeServices seems to be killing off my SAO's and I am getting very
> frustrated.
[quoted text clipped - 19 lines]
> Regards,
> Bob Rundle
Bob Rundle - 28 Jul 2004 22:23 GMT
Hey Sunny,

I thought this trick of returning null from InitializeLifetimeService() in
the MBR object disabled it.  The child object certainly
has this override.  The child object is not a CAO.  The server creates it,
the client simply gains access to it from the root object.

In my test project I follow this same pattern: I marshal a root object which
creates a child and the client accesses both of them.

Here is my test program...which I hesitate to put out here, because the test
program works!

This is the server...

using System;
using System.Collections;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using System.Threading;
using RemotingObjects;

namespace RemotingTestServer
{
class Server : MarshalByRefObject
{
 static void Main(string[] args)
 {
  BinaryServerFormatterSinkProvider serverProv = new
BinaryServerFormatterSinkProvider();
  serverProv.TypeFilterLevel =
System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
  BinaryClientFormatterSinkProvider clientProv = new
BinaryClientFormatterSinkProvider();
  IDictionary props = new Hashtable();
  props["port"] = 1000;
  TcpChannel tcpChannel = new TcpChannel(props, clientProv, serverProv);
  ChannelServices.RegisterChannel(tcpChannel);
  TopLevelClass topLevel = new TopLevelClass();
  topLevel.Log("Marshaling the object.");
  RemotingServices.Marshal((MarshalByRefObject) topLevel, "TopLevel",
typeof(TopLevelClass));
  topLevel.Log("Marshaled.");
  Thread.Sleep(Timeout.Infinite);
 }
}
}
---------------------------------------------------------------
This is the client...

using System;
using RemotingObjects;

namespace RemotingTestClient
{
class Class1
{
 [STAThread]
 static void Main(string[] args)
 {
  TopLevelClass toplevel =
(TopLevelClass)Activator.GetObject(typeof(TopLevelClass),"tcp://localhost:10
00/TopLevel");
  toplevel.Log("Activated toplevel.");
  ChildClass child = toplevel.child;
  child.Log("Referenced child.");
  int sleeptime = 5000;
  while(true)
  {
//    toplevel.Log("Hello toplevel, sleeping " + sleeptime/1000 + " sec.");
   child.Log("Hello child, sleeping " + sleeptime/1000 + " sec.");
   System.Threading.Thread.Sleep(sleeptime);
   sleeptime *= 2;
  }
 }
 public static void Log(string message)
 {
  Console.WriteLine(DateTime.Now.ToString() + "\t- " + message);
 }
}
}
---------------------------------------------------------
These are the root and child objects...

using System;

namespace RemotingObjects
{
public class TopLevelClass : MarshalByRefObject
{
 public ChildClass child;

 public TopLevelClass()
 {
  child = new ChildClass();
 }
 public void Log(string message)
 {
  Console.WriteLine(DateTime.Now.ToString() + "\t(TopLevel) " + message);
 }
 public override object InitializeLifetimeService()
 {
  return null;
 }

}
public class ChildClass : MarshalByRefObject
{
 public void Log(string message)
 {
  Console.WriteLine(DateTime.Now.ToString() + "\t(Child) " + message);
 }
 public override object InitializeLifetimeService()
 {
  return null;
 }
}
}
---------------------------------------------------
Lifetime services never kills the child even as the delay between accesses
approaches one hour.  Again, the test program works and my real program
doesn't.  Either I am overlooking something or the problem occurs when the
server-size tree of objects become large (about 20 or 30 objects in my
case).

Regards,
Bob Rundle
Sam Santiago - 28 Jul 2004 23:46 GMT
Any MBR object created indirectly by an SAO and returned to a client is a
CAO by default for remoting.  Sounds like you will have to use a sponsor:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cp
conrenewingleases.asp


Although what your are doing should work in theory ;-).

Signature

_______________________________
Sam Santiago
ssantiago@n0spam-SoftiTechture.com
http://www.SoftiTechture.com
_______________________________

> Hey Sunny,
>
[quoted text clipped - 58 lines]
>   {
>    TopLevelClass toplevel =

(TopLevelClass)Activator.GetObject(typeof(TopLevelClass),"tcp://localhost:10
> 00/TopLevel");
>    toplevel.Log("Activated toplevel.");
[quoted text clipped - 61 lines]
> Regards,
> Bob Rundle
Sunny - 29 Jul 2004 14:52 GMT
Hi Bob,

most probably you are overlooking something. Try to add functionality to
your test program until it stops working, or try to start stripping down
your main program until the problem disappear.

Sunny

> Hey Sunny,
>
[quoted text clipped - 124 lines]
> Regards,
> Bob Rundle
Bob Rundle - 29 Jul 2004 15:15 GMT
Sunny,

Yes I had overlooked something.  It turns out the problem is the event
wrapper.  I examined the call stack for the error and I discovered that the
"Requested Service Not Found" is not the child object in the server but the
event wrapper the child is trying to call back in the client!

So I have added the InitializeLifetimeService() override returning null in
the event wrapper and I think this will take care of this problem.  Although
I am starting to think that InitializingLifetimeServices() to null everwhere
is not the best course of action.  However it is not clear to me what the
appropriate design pattern is when remoting events are involved.

It also seems that I need some try blocks around the code which raise the
remote events.  I had thought that problems created by raising events where
silently caught, but apparently I am wrong about this.

Regards,
Bob Rundle

> Hi Bob,
>
[quoted text clipped - 66 lines]
> >   {
> >    TopLevelClass toplevel =

(TopLevelClass)Activator.GetObject(typeof(TopLevelClass),"tcp://localhost:10
> > 00/TopLevel");
> >    toplevel.Log("Activated toplevel.");
[quoted text clipped - 61 lines]
> > Regards,
> > Bob Rundle
Sunny - 29 Jul 2004 22:50 GMT
Hi Bob,

> I am starting to think that InitializingLifetimeServices() to null everwhere
> is not the best course of action.  However it is not clear to me what the
> appropriate design pattern is when remoting events are involved.

Create a sponsor at the client. Attach that sponsor to the wrapper
object at the client. And dettach it, when you are done with the
connection. This way, the wrapper will live while you need it. Using
null everywhere is not good :)

Sunny

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.