Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Infinite loop in queries in non localhost #14

Open
aefmind opened this issue Nov 1, 2021 · 9 comments
Open

Infinite loop in queries in non localhost #14

aefmind opened this issue Nov 1, 2021 · 9 comments

Comments

@aefmind
Copy link

aefmind commented Nov 1, 2021

What is the problem?

Infinite loop in queries (useQuery, usePaginatedQuery...). Problem is even present in a clean project generated by blitz new command, accessing from custom domain.

When using blitz dev, sometimes it stops after several reloads. But using blitz build && blitz start loop is always endless.

Paste all your error logs here:

No errors are shown. But content is reloaded infinitely and server console show queries log. Example (in a clean blitz new project):

00:45:06.270 INFO getCurrentUser() Starting with input: null
00:45:06.273 INFO getCurrentUser() Finished: resolver:0ms serializer:1ms total:1ms

00:45:13.466 INFO getCurrentUser() Starting with input: null
00:45:13.468 INFO getCurrentUser() Finished: resolver:0ms serializer:1ms total:1ms

Paste all relevant code snippets here:

Code needed to face the problem is the one generated by blitz new in app/pages/index.ts

What are detailed steps to reproduce this?

  1. blitz new myproject
  2. cd myproject
  3. blitz dev
    or:
    blitz build && blitz start
  4. Go to http://IP:3000

Run blitz -v and paste the output here:

blitz: 0.41.1 (global)
blitz: 0.41.1 (local)

  Package manager: yarn
  System:
    OS: Linux 5.4 Ubuntu 20.04.3 LTS (Focal Fossa)
    CPU: (1) x64 Intel Core Processor (Haswell, no TSX)
    Memory: 414.99 MB / 3.75 GB
    Shell: 5.0.17 - /bin/bash
  Binaries:
    Node: 14.18.1 - /usr/bin/node
    Yarn: 1.22.17 - /usr/local/bin/yarn
    npm: 6.14.15 - /usr/bin/npm
    Watchman: Not Found
  npmPackages:
    @prisma/client: 3.3.0 => 3.3.0
    blitz: 0.41.1 => 0.41.1
    prisma: 3.3.0 => 3.3.0
    react: alpha => 18.0.0-alpha-6bce0355c-20211031
    react-dom: alpha => 18.0.0-alpha-6bce0355c-20211031
    typescript: ~4.3 => 4.3.5

UPDATED:

  • It works fine when is accessed through localhost or 127.0.0.1 addresses.
  • Problem is present only when hostname is not localhost nor 127.0.01 addresses, but through another hostname instead.
  • Login is not working either.
@aefmind aefmind changed the title Infinite loop in useQuery Infinite loop in queries in clean installation Nov 1, 2021
@aefmind aefmind changed the title Infinite loop in queries in clean installation Infinite loop in queries in new project Nov 1, 2021
@aefmind aefmind changed the title Infinite loop in queries in new project Infinite loop in queries Nov 1, 2021
@aefmind aefmind changed the title Infinite loop in queries Infinite loop in queries in Ubuntu 20.04 Nov 1, 2021
@aefmind aefmind changed the title Infinite loop in queries in Ubuntu 20.04 Infinite loop in queries in Ubuntu Nov 1, 2021
@aefmind aefmind changed the title Infinite loop in queries in Ubuntu Infinite loop in queries in Linux but not in Windows Nov 1, 2021
@aefmind aefmind changed the title Infinite loop in queries in Linux but not in Windows Infinite loop in queries in non localhost Nov 2, 2021
@flybayer
Copy link
Member

flybayer commented Nov 2, 2021

@aefmind what are you using to access it via different hostname? Something like ngrok?

@aefmind
Copy link
Author

aefmind commented Nov 2, 2021

@flybayer No. I've hosted it in both OVH VPS (with Ubuntu and Debian) and in my Windows PC.

Even it fails when using 192.168.0.x IP address to access from local network (or same PC) to blitz app hosted in my Windows PC.

VPS has attached a domain.

@aefmind
Copy link
Author

aefmind commented Nov 2, 2021

@flybayer using ngrok, it also fails.

Doing SSH port forwarding (from port in remote server to a local port in my PC) makes it works by simply being able to access using localhost. But using IP address or domain, it has the infinite loop.

I've tried with blitz start -H <hostname> whitout success.

@aefmind
Copy link
Author

aefmind commented Nov 4, 2021

@flybayer I managed to workaround this issue creating two files (dev.js and start.js) and running:

  • node dev.js instead of blitz dev
  • node start.js instead of blitz start

The contents of these files are:

start.js:

"use strict"

var _path = require("path")

var _startServer = require("next/dist/server/lib/start-server").default

const dir = (0, _path).resolve(".")

const port = 3000
const host = "domain.com"
const appUrl = `http://${host === '0.0.0.0' ? 'localhost' : host}:${port}`;

_startServer({ dir }, port, host)
  .then(async (app) => {
    console.log(`started server on ${host}:${port}, url: ${appUrl}`)
    await app.prepare()
  })
  .catch((err) => {
    console.error(err)
    process.exit(1)
  })

and dev.js:

"use strict"

var _path = require("path")

var _startServer = require("next/dist/server/lib/start-server").default
var _output = require("next/dist/build/output")

const dir = (0, _path).resolve(".")

const port = 3000
const host = "domain.com"
const appUrl = `http://${host === '0.0.0.0' ? 'localhost' : host}:${port}`;

_startServer(
  {
    dir,
    dev: true,
    isNextDevCommand: true,
  },
  port,
  host
)
  .then(async (app) => {
    _output.startedDevelopmentServer(appUrl, `${host || "0.0.0.0"}:${port}`)
    // Finalize server bootup:
    await app.prepare()
  })
  .catch((err) => {
    if (err.code === "EADDRINUSE") {
      let errorMessage = `Port ${port} is already in use.`
      console.error(errorMessage)
    } else {
      console.error(err)
    }
    process.nextTick(() => process.exit(1))
  })

It is working fine. So the error is in blitz cli.

@flybayer
Copy link
Member

flybayer commented Nov 6, 2021

Thanks @aefmind for your help! We'll soon be removing the blitz cli wrapper, so probably this will be automatically fixed by that change then.

@yanniz0r
Copy link

I ran into the same issue when using blitzjs in a kubernetes environment. I was able to work around it by manually specifying the host header in my service using the following nginx ingress annotation on the corresponding service:

nginx.ingress.kubernetes.io/upstream-vhost: "localhost:3000"

Maybe this helps some folks running in the same issue :) I guess this also applies to other environments allowing you to overwrite the host header.

@dillondotzip dillondotzip transferred this issue from blitz-js/blitz Jul 7, 2022
@PumAmurcat
Copy link

PumAmurcat commented Jan 31, 2023

Unfortunately this problem is still present in the newest version.
@MartinMuzatko is having the same problem.

@flybayer
Copy link
Member

flybayer commented Feb 2, 2023

@PumAmurcat can you open a new issue in the https://github.com/blitz-js/blitz repo?

@silencej
Copy link

I am also having this issue. I am using node v18.14.1 just FYI. I may help to get to a Minimum Working Example when I have time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants