Skip to content
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

Graceful shutdown of IoT Edge module when restarting module in IoT Edge 1.1 #5274

Closed
fgheysels opened this issue Jul 23, 2021 · 4 comments
Closed
Assignees
Labels
area:app Issue relating to module definition and life cycle customer-reported iotedge question

Comments

@fgheysels
Copy link

When restarting an IoT Edge module via iotedge restart <modulename> I'd expect that the module can be gracefully shut down.

For instance, if I have this simple module:

 static void Main(string[] args)
{
    Init().Wait();

    // Wait until the app unloads or is cancelled
    var cts = new CancellationTokenSource();
    AssemblyLoadContext.Default.Unloading += (ctx) =>
    {
        Console.WriteLine("Assembly unloading");
        cts.Cancel();
    };
    Console.CancelKeyPress += (sender, cpe) => cts.Cancel();
    WhenCancelled(cts.Token).Wait();
    Console.WriteLine("Stopped");
}

When I issue a, iotedge restart command, the 'Assembly Unloading', and 'Stopped' messages are not written to the console, so it looks like a restart just kills the container.

Isn't there a possibility to send a SIGTERM signal when restarting, which could cause the container to gracefully shut down ?

@ancaantochi
Copy link
Contributor

Is this running on linux or windows? You can take a look how edgeAgent and edgeHub implement it for linux and windows: https://github.com/Azure/iotedge/blob/master/edge-util/src/Microsoft.Azure.Devices.Edge.Util/ShutdownHandler.cs

@ancaantochi ancaantochi added area:app Issue relating to module definition and life cycle question labels Jul 26, 2021
@fgheysels
Copy link
Author

Thanks, looks quite interesting. Is this ShutdownHandler class available via some nuget package ?

@ancaantochi
Copy link
Contributor

Hi @fgheysels
No, Microsoft.Azure.Devices.Edge.Util it's not published as nuget package.

@fgheysels
Copy link
Author

I have integrated a modified version of the ShutdownHandler in my own small library and made it available as a nuget package
https://github.com/fgheysels/Fg.IoTEdgeModule/pull/3/files

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:app Issue relating to module definition and life cycle customer-reported iotedge question
Projects
None yet
Development

No branches or pull requests

2 participants