ENOTFOUND redis.railway.internal

videk544
FREE

a month ago

I get successful deployment, but when i check the logs, i am getting this error:
Error: getaddrinfo ENOTFOUND redis.railway.internal

at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:107:26) {

errno: -3007,

code: 'ENOTFOUND',

syscall: 'getaddrinfo',

hostname: 'redis.railway.internal'

}

I have read the documentation and set the family to 0! Still no success.

This is my main.js (where you can see i have correctly set up the family:
const express = require('express');

require('dotenv').config();

const session = require('express-session');

const RedisStore = require('connect-redis').default;

const Redis = require('ioredis');

const cors = require('cors');

const passport = require('passport');

// --- 1. KLJUČNA SPREMEMBA: Uvozite vse iz novega centra za modele ---

const { sequelize } = require('./models'); // Uvozi sequelize instanco, ki pozna VSE modele in asociacije

// Uvoz poti (routes) - to ostane enako

const userRoutes = require('./routes/userRoutes');

const listingRoutes = require('./routes/listingRoutes');

const categoryRoutes = require('./routes/categoryRoutes');

const authRoutes = require('./routes/authRoutes');

const locationRoutes = require('./routes/locationRoutes');

const listingQuestionRoutes = require('./routes/listingQuestionRoutes');

const mailerRoutes = require('./routes/mailerRoutes');

const imageRoutes = require('./routes/imageRoutes');

const passwordResetRoutes = require('./routes/passwordResetRoutes');

const adminRoutes = require('./routes/adminRoutes');

const blogRoutes = require('./routes/blogRoutes');

const app = express();

app.set('trust proxy', 1);

const port = process.env.PORT || 5000;

// --- 2. IZBOLJŠANA CORS POLITIKA za produkcijo in razvoj ---

const allowedOrigins = [

  'http://localhost:3000', // Vaš lokalni frontend

  'http://192.168.0.13:3000', // Vaš lokalni IP

  'https://bazarc-client.onrender.com', // URL vašega frontenda na Renderju

  process.env.FRONTEND_BASE_URL, // URL vašega frontenda, nastavljen v .env datoteki (domena)

];

app.use(

  cors({

    origin: function (origin, callback) {

// Dovoli, če izvor ustreza ali če ni izvora (npr. Postman, mobilne aplikacije)

      if (!origin || allowedOrigins.indexOf(origin) !== -1) {

        callback(null, true);

      } else {

        callback(new Error('CORS policy does not allow access from this origin.'));

      }

    },

    credentials: true,

  })

);

// Body parsers

app.use(express.json());

app.use(express.urlencoded({ extended: true }));

// --- 3. ASINHRONA ZAGONSKA FUNKCIJA (Best Practice) ---

async function startServer() {

  try {

// Poveži se na Redis

    const redisClient = new Redis(process.env.REDIS_URL + "?family=0");

    redisClient.on('error', (err) => console.error('Redis Client Error:', err));

//await redisClient.connect(); // Pridobivanje povezave je sedaj implicitno ob prvem klicu zaradi ioredis namesto redis

    console.log('Successfully connected to Redis.');

// Nastavi Redis kot shrambo za seje (po uspešni povezavi)

    app.use(

      session({

        store: new RedisStore({ client: redisClient }),

        secret: process.env.SESSION_SECRET || 'super-secret-key',

        resave: false,

        saveUninitialized: false,

        cookie: {

          sameSite: process.env.NODE_ENV === 'production' ? 'none' : 'lax', // 'none' za produkcijo, 'lax' za razvoj

          secure: process.env.NODE_ENV === 'production', // true v produkciji

          httpOnly: true,

          maxAge: 1000 60 60 * 24, // 1 dan

        },

      })

    );

    app.use(passport.initialize());

    app.use(passport.session());

    require('./config/passport-setup');

// Endpoint za "health check", ki preprečuje, da Render zaspi.

// Lahko ga kliče storitev, kot je Uptime Robot.

    app.get('/health-check', (req, res) => {

      res.status(200).send('OK');

    });

// Mount routes - zdaj, ko je seja nastavljena

    app.use('/auth', authRoutes);

    app.use('/', userRoutes);

    app.use('/', listingRoutes);

    app.use('/', categoryRoutes);

    app.use('/', locationRoutes);

    app.use('/', listingQuestionRoutes);

    app.use('/', mailerRoutes);

    app.use('/', imageRoutes);

    app.use('/', passwordResetRoutes);

    app.use('/admin', adminRoutes);

    app.use('/', blogRoutes);

// Sinhroniziraj bazo

    await sequelize.sync();

    console.log('Database synchronized successfully.');

// Zaženi strežnik šele, ko je VSE pripravljeno

    app.listen(port, () => console.logServer running on port ${port}));

  } catch (err) {

    console.error('Failed to start the server:', err);

    process.exit(1); // Ustavi aplikacijo, če zagon ne uspe

  }

}

// Zaženi celoten proces

startServer();

$10 Bounty

5 Replies

Railway
BOT

a month ago

Hey there! We've found the following might help you get unblocked faster:

If you find the answer from one of these, please let us know by solving the thread!


a month ago

This thread has been marked as public for community involvement, as it does not contain any sensitive or personal information. Any further activity in this thread will be visible to everyone.

Status changed to Open brody 26 days ago


a month ago

Hey, have you tried setting the family to 0 within the connection options? An example of it can be found in the docs.


uxuz

Hey, have you tried setting the family to 0 within the connection options? An example of it can be found in the docs.

videk544
FREE

a month ago

Yes, i have. You can see it also in the code above.     const redisClient = new Redis(process.env.REDIS_URL + "?family=0");

    redisClient.on('error', (err) => console.error('Redis Client Error:', err));


fra
HOBBYTop 5% Contributor

a month ago

can you try something like?

const redisUrl = new URL(process.env.REDIS_URL! + '?family=6');

    const redisConfig = {
      port: parseInt(redisUrl.port),
      host: redisUrl.hostname,
      username: redisUrl.username || 'default',
      password: redisUrl.password,
      maxRetriesPerRequest: null,
      enableReadyCheck: false,
      family: 6
    };

    // Initialize Redis connection
    this.redis = new Redis(redisConfig);

found here
https://station.railway.com/questions/railway-redis-ioredis-bull-mq-not-connect-f8b79e9a


fra

can you try something like?const redisUrl = new URL(process.env.REDIS_URL! + '?family=6'); const redisConfig = { port: parseInt(redisUrl.port), host: redisUrl.hostname, username: redisUrl.username || 'default', password: redisUrl.password, maxRetriesPerRequest: null, enableReadyCheck: false, family: 6 }; // Initialize Redis connection this.redis = new Redis(redisConfig);found herehttps://station.railway.com/questions/railway-redis-ioredis-bull-mq-not-connect-f8b79e9a

videk544
FREE

25 days ago

Tried that now. Sadly still the same error.

Error: getaddrinfo ENOTFOUND redis.railway.internal

at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:107:26) {

errno: -3007,

code: 'ENOTFOUND',

syscall: 'getaddrinfo',

hostname: 'redis.railway.internal'

}