From http://man7.org/linux/man-pages/man2/ptrace.2.html
PTRACE_TRACEME
Indicate that this process is to be traced by its parent. A
process probably shouldn't make this request if its parent
isn't expecting to trace it.
It is common to use ptrace(PTRACE_TRACEME, 0, 0, 0)
to prevent a program from being debugged,
Any such "common" use is broken, unless the parent process is about to trace this one.
You've promised (to the kernel) "I am about to start tracing this process". The kernel dutifully waits for you to fulfill that promise.
So how should one make the program exit properly?
Have the parent trace it (with all that implies).