This is a wonderful question! At present, the "cleanup" process that Connect fires on processes is not very flexible (i.e. we do not give processes much of a chance to clean up after themselves). I will add your feature request to have this be a bit more flexible.
That said, there are a few knobs that can be turned here. There are several hooks into a dying process. Connect does not allow some of these hooks to fire, but others will. You can try with these examples and use functional hooks to dbDisconnect() or otherwise write code that cleans up after itself.
(NOTE: this one does not work: https://github.com/colearendt/plumber-entrypoint)
Finally, because the process that Connect is managing is the query "client," usually the client does not have any reliable way to "kill" queries that are already running on the database when the application is closed. As a result, running queries will usually persist after a process dies AFAIK.
Would you mind articulating a bit more about the reason for your question? Is it just curiosity? Have you run into particular issues?