Author
Topic: [fix] Wrong killing of extmodule (Read 1562 times)

Some time ago I said about the bug of terminating external module. I've fixed it and changed the logic of quiting from external module as follows.

If exit is initiated from external module it just close their stdout and finish running. Yate as soon as get EOF trying to check is pid terminated or not and waiting up to m_timeout. If EOF was get from socket nothing to wait.

If exit initiated from Yate the engine send to external module %%<quit message and waiting EOF/pid termination as described above.

%%>quit from external module to Yate I've make redundant. But it's possible to interpret it as a "kill me" signal without waiting and without %%<quit as a reply. Let me know how it must be.

The approach let external modules to handle quit messages. It is useful for example if external module registers external lines through user.login message: it's may be important to unregister lines on module quiting (operation=logout).

I'm new in Yate and would like how can I share described improvements? How can I commit it and to know is it a needed feature?

It's 2 improvements: waiting of termination and notification about starting termination. External scripts can be large and complicated. Not only about Yate going to stop but about the external module going to stop it's important to know to close their resources and unregister their lines and accounts (notify SIP clients about loging out). Another case -- channel/playrec external modules started and terminated by Yate for every call and it is also important not only to get notification about quiting but to close their resources properly as well.

For channel scripts you may install message handlers to check termination (see chan.disconnected): when peer channel is hung up your channel script will send a chan.disconnected message: you may catch it

If an external script wants to know when yate is going to stop it may install a handler for engine.stop message.

Quote

For channel scripts you may install message handlers to check termination (see chan.disconnected)

Why do you think 2 different methods better than 1 in my solution? In my view it looks like a crutch. First one (engine.stop message) doesn't cover script restarting from CLI. Second one (chan.disconnected message) doesn't work at all due to CallEndpoint destruction. I installed handler for it (extmodule.cpp from 5.5.0 version without changes), but it doesn't work:

------And I believe Process 9064 has not exited on closing stdin - we'll kill it -- it's not what we want to see in log on the normal case.

My solution allows to write extmodules in a common case more likely to cpp modules: you can do some operations on module constructor and module destructor as well. Moreover I fixed catching chan.disconnected message as well.