-
-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Keep reference to generic server function delegates so they don't get GCed and crash the application #70
base: develop
Are you sure you want to change the base?
Conversation
I'm looking forward to this making it into the library as I currently have it manually implemented in my code. I've run into one small thing while using it though and want to mention it. In my application, I need to be able to Stop/Start the RFC Server. I can do a |
@tom-j-irvine can you please show some code where you would run into the GC issue? Or are you referring to the implementation in #53 ? |
Here is what works: private ISapServer _sapServer;
// ... lots of other code
private void StartRfcServer()
{
// force shutdown if already running
StopRfcServer(false);
// start
_logger.LogInformation("Starting RFC server");
try
{
if (_sapServer == null)
{
_sapServer = SapServer.Create(_config.GetRfcServerParameters());
SapServer.InstallGenericServerFunctionHandler(
_config.GetRfcDestinationParameters(),
(connection, function) => HandleFunction(function)
);
}
_sapServer.Launch();
_logger.LogInformation("RFC server started");
}
catch (Exception ex)
{
_logger.LogError("Exception starting RFC server: {message}", ex.Message);
}
}
private void StopRfcServer(bool logShutdown = true)
{
if (_sapServer != null)
{
if (logShutdown) _logger.LogInformation("Stopping RFC server");
try
{
_sapServer.Shutdown(2000);
if (logShutdown) _logger.LogInformation("RFC server stopped");
}
catch (Exception ex)
{
_logger.LogWarning("Exception shutting down RFC server: {message}", ex.Message);
}
}
} As I said, this works for my purposes. However, I had a version of the code where during shutdown, I would completely dispose the I'm really not sure this matters, but there does seem to be something lingering if you create a server and try to destroy it. I imagine things could get funky if you tried to create multiple servers too, but hopefully no one would try to do that. |
Thanks! I will investigate it. |
8e21814
to
f92a55c
Compare
… GCed and crash the application
f92a55c
to
5b2f46a
Compare
It looks like that calling |
Extracted the fix from #53
Fixes #56