Take the 2-minute tour ×  I have a distributed app where
resources get locked for exclusive use by tasks. Each task runs
in its own process. I'd like to automatically unlock resources
if a task process exits or the server it's running on dies (eg
power failure).  How could I remotely detect such a process
exit/failure within a few seconds?  After some Googling I came
up with a few ideas, but I don't have direct experience with any
of them...    • Use advisory lock functions built into mySQL
(get_lock) or postgres (pg_advisory_lock). These would
automatically release the locks if the database connection
closed, which would happen on a process exit or server crash.
• Use a dedicated distributed lock manager, like ZooKeeper. This
would work, but it seems like more than I need.    • Make a TCP
connection from the task process to a remote monitoring process
with the TCP/socket keepalive option enabled. This seems doable,
but I'd rather build on something that takes care of the low-
level network details for me.