I have a node.js app running in Azure as an App Service. It connects to MongoDB via mongoose + tunnel-ssh. I have multiple App Services deployed in various geo locations and everything works just fine.
When I create a staging slot I get following error from ssh tunnel for the staging instance (note: prod. slot still works fine):
{"code":"EADDRINUSE", "errno":"EADDRINUSE", "syscall":"listen", "address":"127.0.0.1", "port":27017}
To me, it seems that staging slot is running on same VM and tries to use the same port as production and that's why it cannot establish a connection to DB. This means that I probably won't be able to scale out the app as another instance would have the same problem.
How can I solve this both for staging and for other instances (when scaling)?
Staging could use a different port, but how to set it up dynamically so it would work also for scaled instances?