stjet/Faucet-v2

[bug] MongoBug/Error?

Closed this issue · 21 comments

Error, trying to run Nano-Faucet

Error (replit)

/home/runner/Faucet-v2/node_modules/mongodb/lib/sdam/topology.js:292
                const timeoutError = new error_1.MongoServerSelectionError(`Server selection timed out after ${serverSelectionTimeoutMS} ms`, this.description);
                                     ^

MongoServerSelectionError: connection <monitor> to 23.23.201.116:27017 closed
    at Timeout._onTimeout (/home/runner/Faucet-v2/node_modules/mongodb/lib/sdam/topology.js:292:38)
    at listOnTimeout (node:internal/timers:557:17) {
  reason: TopologyDescription {
    type: 'ReplicaSetNoPrimary',
    servers: Map(3) {
      'ac-a6lxmzw-shard-00-00.slzsv1i.mongodb.net:27017' => ServerDescription {
        address: 'ac-a6lxmzw-shard-00-00.slzsv1i.mongodb.net:27017',
        type: 'Unknown',
        hosts: [],
        passives: [],
        arbiters: [],
        tags: {},
        minWireVersion: 0,
        maxWireVersion: 0,
        roundTripTime: -1,
        lastUpdateTime: 14074569,
        lastWriteDate: 0,
        error: MongoNetworkError: connection <monitor> to 23.23.201.116:27017 closed
            at Connection.onClose (/home/runner/Faucet-v2/node_modules/mongodb/lib/cmap/connection.js:136:19)
            at TLSSocket.<anonymous> (/home/runner/Faucet-v2/node_modules/mongodb/lib/cmap/connection.js:63:46)
            at TLSSocket.emit (node:events:390:28)
            at TLSSocket.emit (node:domain:475:12)
            at node:net:687:12 {
          [Symbol(errorLabels)]: Set(1) { 'ResetPool' }
        },
        topologyVersion: null,
        setName: null,
        setVersion: null,
        electionId: null,
        logicalSessionTimeoutMinutes: null,
        primary: null,
        me: null,
        '$clusterTime': null
      },
      'ac-a6lxmzw-shard-00-01.slzsv1i.mongodb.net:27017' => ServerDescription {
        address: 'ac-a6lxmzw-shard-00-01.slzsv1i.mongodb.net:27017',
        type: 'Unknown',
        hosts: [],
        passives: [],
        arbiters: [],
        tags: {},
        minWireVersion: 0,
        maxWireVersion: 0,
        roundTripTime: -1,
        lastUpdateTime: 14073248,
        lastWriteDate: 0,
        error: MongoNetworkError: connection <monitor> to 35.175.54.237:27017 closed
            at Connection.onClose (/home/runner/Faucet-v2/node_modules/mongodb/lib/cmap/connection.js:136:19)
            at TLSSocket.<anonymous> (/home/runner/Faucet-v2/node_modules/mongodb/lib/cmap/connection.js:63:46)
            at TLSSocket.emit (node:events:390:28)
            at TLSSocket.emit (node:domain:475:12)
            at node:net:687:12 {
          [Symbol(errorLabels)]: Set(1) { 'ResetPool' }
        },
        topologyVersion: null,
        setName: null,
        setVersion: null,
        electionId: null,
        logicalSessionTimeoutMinutes: null,
        primary: null,
        me: null,
        '$clusterTime': null
      },
      'ac-a6lxmzw-shard-00-02.slzsv1i.mongodb.net:27017' => ServerDescription {
        address: 'ac-a6lxmzw-shard-00-02.slzsv1i.mongodb.net:27017',
        type: 'Unknown',
        hosts: [],
        passives: [],
        arbiters: [],
        tags: {},
        minWireVersion: 0,
        maxWireVersion: 0,
        roundTripTime: -1,
        lastUpdateTime: 14073920,
        lastWriteDate: 0,
        error: MongoNetworkError: connection <monitor> to 54.147.79.152:27017 closed
            at Connection.onClose (/home/runner/Faucet-v2/node_modules/mongodb/lib/cmap/connection.js:136:19)
            at TLSSocket.<anonymous> (/home/runner/Faucet-v2/node_modules/mongodb/lib/cmap/connection.js:63:46)
            at TLSSocket.emit (node:events:390:28)
            at TLSSocket.emit (node:domain:475:12)
            at node:net:687:12 {
          [Symbol(errorLabels)]: Set(1) { 'ResetPool' }
        },
        topologyVersion: null,
        setName: null,
        setVersion: null,
        electionId: null,
        logicalSessionTimeoutMinutes: null,
        primary: null,
        me: null,
        '$clusterTime': null
      }
    },
    stale: false,
    compatible: true,
    heartbeatFrequencyMS: 10000,
    localThresholdMS: 15,
    setName: 'atlas-wtnme1-shard-0',
    maxElectionId: null,
    maxSetVersion: null,
    commonWireVersion: 0,
    logicalSessionTimeoutMinutes: null
  },
  code: undefined,
  [Symbol(errorLabels)]: Set(0) {}
}

Config

{
  "self": "https://faucet-v2.imintheicu.repl.co",
  "name": "Prussia's <coin> Faucet",
  "db": "mongodb",
  "port": 8080,
  "owner": "YOUR NAME",
  "logo": false,
  "unopened_reduced_payouts": false,
  "notice": {
    "title": "More front-end potassium",
    "content": "All the faucets have a new look, go check them out!",
    "link": "https://banano.cc"
  },
  "sponsor": {
    "name": "Prussia",
    "link": "https://prussia.dev"
  },
  "captcha": {
    "hcaptcha_sitekey": "b4db4920-1a73-4b9b-995b-...",
    "use_splash": true,
    "prussia_captcha": "https://captcha.prussia.dev"
  },
  "banano": {
    "claim_frequency": 86400000,
    "enabled": false,
    "default": false,
    "auto_receive": false,
    "address": "",
    "rpc": "",
    "payouts": {
      "min_payout": 0.02,
      "max_payout": 0.07,
      "percentage": false
    }
  },
  "nano": {
    "claim_frequency": 86400000,
    "enabled": true,
    "default": true,
    "address": "nano_3p76j3jecwfdq5c9c99pyythx1shimxfz4ec5xeqbkebkgw3nie5jbh4z4kk",
    "rpc": "https://proxy.nanos.cc/proxy",
    "payouts": {
      "min_payout": 0.0001,
      "max_payout": 0.0002,
      "percentage": false
    }
  },
  "xdai": {
    "claim_frequency": 86400000,
    "enabled": false,
    "address": "",
    "rpc": "",
    "payouts": {
      "min_payout": 0.005,
      "max_payout": 0.005,
      "percentage": false
    }
  },
  "vite": {
    "claim_frequency": 86400000,
    "enabled": false,
    "address": "",
    "rpc": "",
    "payouts": {
      "min_payout": 0.01,
      "max_payout": 0.05,
      "percentage": false
    },
    "token": {
      "id": "",
      "amount": 1,
      "decimals": 0,
      "alias": "Token name"
    },
    "optional": true
  },
  "secrets": {
    "use_env": true
  }
}
stjet commented

Hi @ImInTheICU ! Thanks for opening an issue. Since you are using replit, I'm pretty sure I know the issue.

Assuming you set mongo_connection_string correctly in the secrets tab, **this is an issue on replit's end. Sometimes replit has problems connecting to mongodb on certain machines.

The solution is, unfortunately, going into shell and typing in kill 1 to kill the container and have replit switch to a container that does connect to mongodb properly. Luckily, you can kind of automate this, by replacing the first 14 lines of utils/faucet.js to this:

const config = require('../config.js');
const mongo = require('./mongo.js');
const { exec } = require('child-process');

let db = mongo.getDb();

let ready = false;

// Separate collections for each currency
let collections = {};
db.then((db) => {
  ready = true;
  // Check what currencies are supported, and get a collection for each one
  let enabled_coins = config.enabled_coins;
  for (let i = 0; i < enabled_coins.length; i++) {
    collections[enabled_coins[i]] = db.collection(enabled_coins[i]);
  }
});

setTimeout(function() {
  if (!ready) {
    //if replit does not connect to mongodb within 6 seconds, kill the container and wait for a restart
    exec('kill 1');
  }
}, 6000);

And if you put a http pinger like UptimeRobot on the faucet's url, it will automatically restart within 5 minutes of it being killed.

Or, probably better, you can use another host. Render is a good free one that is currently running my faucet. If you put cloudflare caching in front of it, their 100 GB traffic limit is no problem.

Would something like Vercel work?
https://vercel.com/

stjet commented

As far as I know, Vercel only lets you deploy serverless sites which this isn't, at least not without modification. It might be technically possible to deploy this on Vercel but it doesn't seem like a good idea, from a brief read of their docs.

Damn, that's rough.
Ile attempt Render, never heard or tried it before.

stjet commented

It's harder to modify the app in render, but render has been pretty good for deploying, at least in my experience. If you still want to use replit, to be clear, you can, but that fix is more of a "duct tape fix" and doesn't really prevent the problem, just mitigates it.

I'll ask around to see if anyone else has any free host recommendations and get back to you.

Ile attempt render here soon.
Is there any major limitations of render?

stjet commented

You can more or less only deploy one dynamic website per account (anything with a backend, so this faucet), and each account can only have 100 GB of egress (outbound) bandwidth. 100 GB is a lot though, and even if you have many visitors and larger pictures on the site, that can be solved by using Cloudflare to cache all that and prevent it from adding to the 100 GB limit. Also just generally make sure any assets on your website are compressed and all that.

Build times are also a little longer, but once it's built, it will stay on forever (unlike replit), unless you stop it or there is an error in the code that crashes it. It can also deploy automatically once you commit to a git repo which is pretty cool too. And of course it supports env variables and secret files.

You can more or less only deploy one dynamic website per account (anything with a backend, so this faucet), and each account can only have 100 GB of egress (outbound) bandwidth. 100 GB is a lot though, and even if you have many visitors and larger pictures on the site, that can be solved by using Cloudflare to cache all that and prevent it from adding to the 100 GB limit. Also just generally make sure any assets on your website are compressed and all that.

Build times are also a little longer, but once it's built, it will stay on forever (unlike replit), unless you stop it or there is an error in the code that crashes it. It can also deploy automatically once you commit to a git repo which is pretty cool too. And of course it supports env variables and secret files.

Ah thats sweet, also this faucet is not static ? right?
image

stjet commented

Ah, it won't be free, but sometimes when buying your domain name, you get free or cheap hosting, and they get you a cpanel account or something like that. It's not as easy to set up as replit or render, but it's something to consider.

stjet commented

Yup, it is not static, you want a "Web Services".

Nice thanks for the help.

stjet commented

No problem! Since you've already created a Render account, it's probably best to stick with that, but for future reference, a friend of mine recommended https://railway.app which seems to be fine for this too.

Edit: oh it seems to be only 20 days a month, but if you make a one-time (?) payment of $5 the time is unlimited.

stjet commented

Anyways, if you need further help you can just mention me in, I guess, this issue, or if you have a discord, might be easier to contact me on discord if the issue is more private or complicated.

Anyways, if you need further help you can just mention me in, I guess, this issue, or if you have a discord, might be easier to contact me on discord if the issue is more private or complicated.

👍

Deploy'd and kept getting mongo problems with the IP-Address.
Fixed that, but now after doing the captcha and using the faucet I get a internal server error with 0 error.

stjet commented

Mongo thing is that you need to whitelist all IPs (or just the ones render gives you). Can you be more specific with the captcha error? I assume you are using hcaptcha, you set up an account, did the site key, set the hcaptcha secret in env and so on, right?

HCaptcha,
And its not the captcha having problems.

After the captcha and i submit my request to the faucet for some nano, it internal server errors with no error in console

See here: https://nanofaucet.onrender.com

2023-04-19.14-51-14.mp4
stjet commented

Hmm, really no logs in render? Are you sure?

If you set all the env variables, config file correctly it should work. I checked the nano account and it was opened, so that's not the problem.

If you are certain there's no obvious issues in the config file, no logs, all env variables are valid and present, could you contact me on Discord (or I can contact you, either way), and I can try to figure out the issue.

Got it working!
Thanks for all the help, very little developer's / contributors on github take time to help people and solve problems on there project!

Turns out the package file was missing node-fetch.
But was suppressed by Render?
And never display'd as a error.

stjet commented

Ah! Thanks for the report, I will make sure node-fetch gets added to the package.json then.