Unable to Connect with GCP Virtual Machine


I have been trying to connect my GCP VM application for some time. I’ve whitelisted the IPs of my personal machine and the external IP ( of the virtual machine. This VM IP is pingable.

When I start my app on the VM server, it crashes with the following error:

server started on port 8080
                op.cb(new error_1.MongoNetworkError(`connection ${this.id} to ${this.address} closed`));

MongoNetworkError: connection 1 to closed
    at Connection.handleIssue (/home/overlord/github_sleepywakes_thunderroost/node_modules/mongoose/node_modules/mongodb/lib/cmap/connection.js:122:23)
    at TLSSocket.<anonymous> (/home/overlord/github_sleepywakes_thunderroost/node_modules/mongoose/node_modules/mongodb/lib/cmap/connection.js:63:39)
    at TLSSocket.emit (node:events:394:28)
    at node:net:662:12
    at TCP.done (node:_tls_wrap:580:7)
[nodemon] app crashed - waiting for file changes before starting...

When I open the MongoDB whitelist to, my VM server starts and I’m able to do a web preview of my app through GCP on port 8080.

What’s the interpretation of this error message? Thanks in advance for any help!

I’ve just tried creating another VM instance from scratch, and I have the same problem – server crash with error above.

I should also note that when I open the whitelist to, I can access through GCP’s web preview, but I CANNOT access the VM’s external IP address (the one I whitelisted in Mongodb) through my browser. It times out. I’m not sure if this is related, or if it’s a second problem I will have to resolve after getting the whitelist issue resolved.

Thanks for any guidance. I’m fully stuck.

I’ve been looking at the Mongoose code that generated the error, in:

I’m not experienced enough to know what is fully going on, but it appears the connection is closing (line before is if (issue.isClose) {). The IP address in the error message ( appears to be the Google Data Center where my VM is running. I’m not sure what this means by thought it my help for anyone who has ideas on next steps for me.

If it helps, here’s the code within the mongoose file listed above:

    handleIssue(issue) {
        if (this.closed) {
        if (issue.destroy) {
            this[kStream].destroy(typeof issue.destroy === 'boolean' ? undefined : issue.destroy);
        this.closed = true;
        for (const [, op] of this[kQueue]) {
            if (issue.isTimeout) {
                op.cb(new error_1.MongoNetworkTimeoutError(`connection ${this.id} to ${this.address} timed out`, {
                    beforeHandshake: this.hello == null
            else if (issue.isClose) {
                op.cb(new error_1.MongoNetworkError(`connection ${this.id} to ${this.address} closed`));
            else {
                op.cb(typeof issue.destroy === 'boolean' ? undefined : issue.destroy);

with the issue.isClose line throwing the error.

Another update on the off-chance that someone is reading this. I did an IP check through Cloud Shell directly from the VM, and it gives me a different IP address than GCP’s “external IP.” Whitelisting this new IP allows me to connect. Woohoo. (I’m curious why this is the case, but just happy it is finally working.)

However, I still cannot access either the GCP VM stated external IP address (‘cannot connect’ error) or the Cloud Shell reported IP address (‘took too long to connect’ error) through Chrome. I can connect through GCP’s Web Preview, though.

1 Like

Glad to hear you were able to eventually connect Steve.

Regarding the above statement, I just want to clarify what you mean by “through Chrome”. Do you mean the Atlas UI itself isn’t able to be accessed from that same machine?


Thanks, Jason. A coder friend came over just now and dug into my problem. I was using Cloud Shell, and he discovered that we needed to SSH into the VM so that the actual IP address was used. All of my file cloning, etc., done through Cloud Shell, was not putting it on the server itself. Once he cloned my files using SSH, all was good.

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.