Taking a look to your logs it seems that the issue could be related to not being closing the connections.
Terminating session due to error: InternalError: failed to create service entry worker thread
I think you are using your custom NodeJS application? If yes be sure to close the connections after use them.
Apart from that, regarding:
TypeError: Cannot read property 'db' of undefined
it seems to be a problem with your code, do you have a variable
db with an actual value? Could you share the full trace of that error?