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

Improve termination of Swift servants in response to signals #75

Open
pepone opened this issue Sep 5, 2019 · 0 comments
Open

Improve termination of Swift servants in response to signals #75

pepone opened this issue Sep 5, 2019 · 0 comments

Comments

@pepone
Copy link
Member

pepone commented Sep 5, 2019

The pattern used in IceStorm/clock subscriber, isn't simple and also is not thread safe, there is a chance for exit call run when GDC global queue is still releasing the communicator reference in the signal event handler

let sigintSource = DispatchSource.makeSignalSource(signal: SIGINT,
queue: DispatchQueue.global())
let sigtermSource = DispatchSource.makeSignalSource(signal: SIGTERM,
queue: DispatchQueue.global())
sigintSource.setEventHandler { communicator.shutdown() }
sigtermSource.setEventHandler { communicator.shutdown() }
sigintSource.resume()
sigtermSource.resume()

For the publisher we do all the work in the main thread including the signal handling, but it is still not straightforward and will be good if we come up with a better solution

let sigintSource = DispatchSource.makeSignalSource(signal: SIGINT, queue: DispatchQueue.main)
sigintSource.setEventHandler {
communicator.destroy()
}
sigintSource.resume()
let sigtermSource = DispatchSource.makeSignalSource(signal: SIGTERM, queue: DispatchQueue.main)
sigtermSource.setEventHandler {
communicator.destroy()
}
sigtermSource.resume()

@pepone pepone added this to the 4.0.0 milestone Apr 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant