Remoting / StackOverflowException problem

G

Guest

I'm having a problem with a pair of applications I'm developing. I have a
server application which interacts with several instruments, and a client app
which connects to the server and provides a UI for interacting with the
instruments. Readings from the instruments are periodically sent to the
clients, and clients will send commands to the server based on user input.
In normal usage there will be around 6 clients connected, with a maximum of
about 12, and the clients are connected to the server via a closed gigabit
ethernet network.

I have a shared assembly which defines two interface classes: IRemoteClient,
and IRemoteServer:

namespace MyApp {
namespace Remoting
{
public interface class IRemoteClient
{
public:
void Object_For_Client (Common::ExchangeObject ^exch_ob);
};

public interface class IRemoteServer
{
public:
int AddClient (Remoting::IRemoteClient ^client);
void RemoveClient (int client_id);
void Object_For_Device (Common::ExchangeObject ^exch_ob);
};
}}

My client app has an object which implements the IRemoteClient interface,
and the server has an object which implements the IRemoteServer interface.
Those two objects also inherit from System::MarshalByRefObject, and override
InitializeLifetimeService to live forever. The server creates its remoting
object and publishes it on a TCP channel via
System::Runtime::Remoting::RemotingServices::Marshal. The client gets a
reference to the server, then registers with it by calling AddClient, passing
it the client's remoting object. The server adds the client to a list of
connected clients, and periodically sends out updated instrument data to all
connected clients, using the Object_For_Client method of the client's
remoting object. The client's remote object then raises an event which the
main client app catches.

The client is a windows forms application. At startup, after connecting to
the server, it creates an instance of its main form, stores it in
this->main_form, then Calls System::Windows::Forms::Application::Run on it.
When it catches an event from the remote interface, it checks
this->main_form->InvokeRequired, and uses an invoke if necessary, so it can
update controls from the proper thread:

void ClientApp::Send_Object_To_Client(Common::ExchangeObject ^object)
{
if (!this->main_form)
{
// main form doesn't exist yet, so we're still starting up
return;
}

// Make things thread safe
if (this->main_form->InvokeRequired)
{
array<System::Object ^> ^args = { object };
try
{
this->main_form->BeginInvoke(
gcnew Common::ObjectHandler(this,
&ClientApp::Send_Object_To_Client),
args);
}
catch (System::ObjectDisposedException ^)
{
}
return;
}

// process the new data
if (this->Frontends[object->DestDevice])
{
this->Frontends[object->DestDevice]->Process_Object(object);
}
}

The client used to use Invoke, and I changed it to BeginInvoke to clear up a
deadlock situation during shutdown.

The problem I'm having is that the server gets a
System::StackOverflowException at its call to Client->Object_For_Client after
everything has been up and running for a few hours. I suspected that the
problem might be that I was calling BeginInvoke without ever calling
EndInvoke, but I was unable to reproduce the problem in a little test
application which did solely that.

I'm unsure where to procede from here, because the StackOverflowException
blows away most of my program state when it happens, so I can't figure out
what's happening at the time of the problem. Because it takes so long to
happen, I generally start everything running when I leave for the day, and
see the problem when I come in the next morning.

I know the normal cause of a stack overflow is runaway recursion, but I
don't think that's the case here, for a couple of reasons. First, there's no
intentional recursion anywhere in the client or server, and I'm quite sure
there isn't any that's unintentional. Second, when it happens, the server
has been sending out messages which are virtually identical for a few hours.
If it was a recursion problem, I would expect to see the problem much sooner.

Any suggestions of what the problem might be or where to go from here in
trying to find it would be greatly appreciated.

Thanks,
-Thomee-
 
L

Luke Zhang [MSFT]

Hello,

For such a random exception, I suggest you may contact our PSS department.
They can assist you perform a memory dump when the exception occur and
analyst it to see what happened. I didn't see any visible problem from your
description, the problem may need deep analysis so that I believe
performing a memory dump may be the best approach to see what happened.

To submit a support incident to our PSS:

https://msdn.microsoft.com/subscriptions/account/msdn/en-us/supportbenefits.
aspx?cu=en-us

Regards,

Luke Zhang
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top