Create a new process group on startup to allow safe shutdown when used with Ctrl-C console applications #262
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue:
Pressing 'Ctrl-C' to issue a console application termination on UNIX systems will send a SIGINT signal to all processes in the parent's process group.
When using the KPL, this means that the child C++ binary process will receive a SIGINT when pressing Ctrl-C. It will attempt to flush its internal buffers, but the libraries at the other side of the pipe that the programmer interacts with directly cannot identify all the final records as pushed or not.
This makes the KPL currently incompatible with applications that have a lifecycle that may include Ctrl-C to terminate.
Changes:
This PR includes a call to setpgid() on the child process on UNIX systems. This will create a new process group for the child process, which means it will not receive a SIGINT when the parent receives a Ctrl-C; it can still be send a SIGINT specifically with its PID, but it will not panic and flush when the parent receives Ctrl-C.
This change seems to have no adverse side effects on all the testing we have performed, the KPL still closes successfully on application shutdown and no zombie KPL processes are left over; this change should only affect the behaviour of the KPL when used in an application where the user presses Ctrl-C, and should stop the data loss experienced then.
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.