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

air started but NOT reloading #274

Closed
kockok opened this issue May 8, 2022 · 31 comments
Closed

air started but NOT reloading #274

kockok opened this issue May 8, 2022 · 31 comments

Comments

@kockok
Copy link

kockok commented May 8, 2022

Screenshot 2022-05-08 at 5 44 13 PM

It seems to be working, but there's no rebuilding after I change the code.

Dockerfile:

FROM golang:alpine
RUN apk add --no-cache git
WORKDIR /app
COPY go.* .
COPY *air.toml .
RUN go mod download
COPY . .
RUN go install github.com/cosmtrek/air@latest
CMD ["air", "-c", ".air.toml"]

docker-copose.yml

services:
  api:
    build: .
    ports:
      - "3000:3000"
    depends_on:
      - mongo
    volumes:
      - .:/app
    restart: on-failure
    environment:
      - MONGO_URI=mongodb://admin:password@mongo:27017/test?authSource=admin

  mongo:
    image: mongo
    restart: on-failure
    environment:
      MONGO_INITDB_ROOT_USERNAME: admin
      MONGO_INITDB_ROOT_PASSWORD: password
    ports:
      - "27017:27017"
    volumes:
      - mongo:/data/db
      - mongo:/data/configdb

volumes:
  mongo:

I'm using M1 macbook, just wondering if it's an ARM/AMD thing.

@badcc
Copy link

badcc commented May 15, 2022

I am also experiencing this... on Intel.. I wonder if related to a new version of Docker or something? Maybe fsnotify for some particular reason/stack not working with mounted volumes? Will continue looking but thought I'd post here to show support. Works fine locally, without Docker.

EDIT: Seems potentially related from mounted volumes on Docker for Windows/WSL not firing the necessary I/O events.. can anyone else confirm?

EDIT2: The real issue is here microsoft/WSL#4739 and I was able to resolve my problem by integrating Docker with my Ubuntu WSL2 distro, and putting my file system in the Linux-mounted \wsl$ file system. Now fsnotify is properly detecting changes, and Air works!

@kockok
Copy link
Author

kockok commented May 16, 2022

I am also experiencing this... on Intel.. I wonder if related to a new version of Docker or something? Maybe fsnotify for some particular reason/stack not working with mounted volumes? Will continue looking but thought I'd post here to show support. Works fine locally, without Docker.

EDIT: Seems potentially related from mounted volumes on Docker for Windows/WSL not firing the necessary I/O events.. can anyone else confirm?

EDIT2: The real issue is here microsoft/WSL#4739 and I was able to resolve my problem by integrating Docker with my Ubuntu WSL2 distro, and putting my file system in the Linux-mounted \wsl$ file system. Now fsnotify is properly detecting changes, and Air works!

Good for you, if it's not an ARM thing, then I'll wait for Air to get updated :)

@kockok kockok closed this as completed May 16, 2022
@ctiller15
Copy link

Checking in - @kockok did you ever find a resolution for this? I'm running into the exact same problem setting up air to run w/ docker on my M1.

@kockok
Copy link
Author

kockok commented Aug 3, 2022

Checking in - @kockok did you ever find a resolution for this? I'm running into the exact same problem setting up air to run w/ docker on my M1.

Negative, I switched to CompileDaemon tentatively, but really want air instead...

@ctiller15
Copy link

Checking in - @kockok did you ever find a resolution for this? I'm running into the exact same problem setting up air to run w/ docker on my M1.

Negative, I switched to CompileDaemon tentatively, but really want air instead...

Gotcha. Is there an existing issue that addresses this? If not shouldn't this one be reopened?

@windowshopr
Copy link

I'm new to Go, but I'm having the same problem.

Windows 10, Go 1.19, AMD

My simple sample project structure and code looks like this:

image

...which results in a simple page that looks like this:

image

So I go to make a change in main.go, like changing hello world to something else and save:

image

...but the terminal output doesn't change at all, like Air SAYS it's "watching" for changes, but when I save, nothing happens in the output.

So then, even after clearing browser cache, and using a new incognito window, the change doesn't even reflect on the page:

image

Forgive my newbie-ness, but what's happening here?

@xiantang xiantang reopened this Aug 8, 2022
@windowshopr
Copy link

One thing that might be worth mentioning here is that I’m running this inside a docker-compose. Maybe it doesn’t apply changes saved in a container, but only on local instances of the app?

@badcc
Copy link

badcc commented Aug 8, 2022

I'm fairly confident that the issue is due to fsnotify not picking up file system events between the Linux/Ubuntu Docker file system (LFTS), and the Windows file system (NFTS) which is making the changes through the mounted volume (such as.. through VSCode/etc.). I believe the only good solution is for air to implement polling... so until then, as @kockok has done, I have switched to CompileDaemon (or similar) which offers polling (this is less efficient as it doesn't utilize events and instead just checks all your project files for changes every X milliseconds, but necessary for mixing file systems).

(Or, fsnotify could add polling themselves, but this has been open since 2014: fsnotify/fsnotify#9 (comment))

(Alternatively, you can standardize on a singular file system.. such as pairing Docker with WSL2 and working out of the \\wsl$ directory as I described above. I found this had some other side effects down the road so I reverted, but it is a solution)

Thus, this issue is better closed in favor of/described by #190 (or the earlier, but less discussed, #67).

@ShayperCool
Copy link

Just noticed my Docker Desktop in Linux use virtiofs in container, so I tried disable it thourgh "~/.docker/desktop/settings.json" setting "useVirtualizationFrameworkVirtioFS": true -> "useVirtualizationFrameworkVirtioFS": false. After that Docker Desktop stop running. And I just installed usual docker :), and now hot reload is working.
So, maybe in Windows or Mac you can change this parameter and Docker Desktop will run, and you maybe will get working hot reload, but I can't test it myself.

@azmiadhani
Copy link

Just noticed my Docker Desktop in Linux use virtiofs in container, so I tried disable it thourgh "~/.docker/desktop/settings.json" setting "useVirtualizationFrameworkVirtioFS": true -> "useVirtualizationFrameworkVirtioFS": false. After that Docker Desktop stop running. And I just installed usual docker :), and now hot reload is working. So, maybe in Windows or Mac you can change this parameter and Docker Desktop will run, and you maybe will get working hot reload, but I can't test it myself.

I tried this. Unfortunately does not work, after I set useVirtualizationFrameworkVirtioFS:false docker always failed to start.

@azmiadhani
Copy link

Updating Docker Engine to the latest version seems to solve the issues with air to me.
image
image

@junereycasuga
Copy link

mine still doesn't work even after updating the docker engine version to 20.10.22

@subkaitaku
Copy link

subkaitaku commented Jan 21, 2023

I tried both versions and neither detected a difference on Docker.
macOS: 13.1
M1 MacBook

Server: Docker Engine - Community
 Engine:
  Version:          20.10.12
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.16.12
  Git commit:       459d0df
  Built:            Mon Dec 13 11:43:07 2021
  OS/Arch:          linux/arm64
  Experimental:     false
Server: Docker Desktop 4.16.2 (95914)
 Engine:
  Version:          20.10.22
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.18.9
  Git commit:       42c8b31
  Built:            Thu Dec 15 22:25:43 2022
  OS/Arch:          linux/arm64
  Experimental:     false

@azmiadhani
Copy link

Sorry to hear that. By the way, this is my docker-compose.yaml file just in case anyone needs it.
image
Also, this is my Dockerfile.
image

@devmeireles
Copy link

I'm facing the same issue in Windows 11 on Docker v20.10.22

@kaspers1778
Copy link

WIndows 10, Docker v20.10.22, ditto. Working if run air from terminal, not working if run it from docker compose.

@CoolGoose
Copy link

CoolGoose commented Feb 19, 2023

Unfortunately, I have the same problem.
Initial build works, but no luck getting anything updated.

Edition	Windows 10 Pro
Version	22H2
Installed on	‎2020-‎08-‎23
OS build	19045.2604
Experience	Windows Feature Experience Pack 120.2212.4190.0
Docker Engine
v20.10.22

.air.toml

[build]
cmd = "go build -o ./tmp/api ./cmd/api"
bin = "tmp/api"

docker-compose.yml

services:
  app:
    build:
      context: .
      dockerfile: Dockerfile
      target: air
    ports:
      - 8080:8080
    volumes:
      - ./:/app

@devmeireles
Copy link

I haven't tried yet but maybe for when working from vscode Devcontainer could be the solution taking into account it'll handle the container file system, here's a small example about that: https://github.com/devmeireles/go-shop-store

By the end of the day I moved to CompileDaemon

@edegp
Copy link

edegp commented Mar 2, 2023

I had same issue but only forget docker-compose a volume-mount setting .
My PC: mac M1
docker-comopse.yml

.
├── app/
│   ├── ...go application
│   └── air.toml
├── dockerfile
└── docker-compose.yml
web:
    container_name: go_app
    volumes:
       ...
      - ./app:/app  #← add this

@NicholasKoldys
Copy link

NicholasKoldys commented May 6, 2023

VScode alternative solution is to use Dev Container and Docker Extensions (by Microsoft.com).

Connect to the container via instructions provided by Dev Container and navigate to the working directory through the explorer (you may be defaulted to /root/) and file changes will reload with Air.

With the volume type mount, I haven't seen any issues arise in the remote vscode instance; however, this still has no effect on the host vscode instance, as there seems to be no response with file changes in Air. So you must use the remote vscode instance.

I haven't tested with a remote docker instance either, as I am hosting docker on the host machine.

note: vscode dev container instance will not have your extensions.

@wassimbj
Copy link

I'm on windows, i thought it may be a permission issue, so i started vscode and docker as administrator, but no luck. the only solution i found was to make air to use polling instead of events, so what you should do is basically change poll to true and it should work

# Poll files for changes instead of using fsnotify.
poll = true

@arun-art06
Copy link

I'm on windows, i thought it may be a permission issue, so i started vscode and docker as administrator, but no luck. the only solution i found was to make air to use polling instead of events, so what you should do is basically change poll to true and it should work

# Poll files for changes instead of using fsnotify.
poll = true

Excellent answer. It works for me.

i have just changed in the .air.toml
[build]
poll = true

@swarajkumarsingh
Copy link

The perfect solution 💕

Issue: Air is starting but not reloading on changes in the project

Solution: In .air.toml file add poll = true This is because Windows has some restrictions and to overcome that we set poll to true

Solution in code:

poll = true

@xiantang
Copy link
Collaborator

I think it's solved

@XiaoxiaYao
Copy link

It's the docker issue for me. Just updat to the latest docker app.

@zhitoo
Copy link

zhitoo commented Nov 2, 2023

I'm new to Go, but I'm having the same problem.

Windows 10, Go 1.19, AMD

My simple sample project structure and code looks like this:

image

...which results in a simple page that looks like this:

image

So I go to make a change in main.go, like changing hello world to something else and save:

image

...but the terminal output doesn't change at all, like Air SAYS it's "watching" for changes, but when I save, nothing happens in the output.

So then, even after clearing browser cache, and using a new incognito window, the change doesn't even reflect on the page:

image

Forgive my newbie-ness, but what's happening here?

i have this problem just quite terminal and run air command again.

@swarajkumarsingh
Copy link

I'm new to Go, but I'm having the same problem.

Windows 10, Go 1.19, AMD

My simple sample project structure and code looks like this:

image

...which results in a simple page that looks like this:

image

So I go to make a change in main.go, like changing hello world to something else and save:

image

...but the terminal output doesn't change at all, like Air SAYS it's "watching" for changes, but when I save, nothing happens in the output.

So then, even after clearing browser cache, and using a new incognito window, the change doesn't even reflect on the page:

image

Forgive my newbie-ness, but what's happening here?

i have this problem just quite terminal and run air command again.

Try changing your browser or just follow my solution

@parhamAllahyar
Copy link

poll = true

it works for me, thanks

@masonbesmer
Copy link

masonbesmer commented Dec 18, 2023

Polling is not a performant solution. What is the underlying issue here?

I have tested on Arch and Windows and both platforms suffer from the same issue.

[mason@mason-surfarch ~]$ docker version
Client:
Version: 24.0.7
API version: 1.43
Go version: go1.21.3
Git commit: afdd53b4e3
Built: Sun Oct 29 15:42:02 2023
OS/Arch: linux/amd64
Context: default

Server:
Engine:
Version: 24.0.7
API version: 1.43 (minimum version 1.12)
Go version: go1.21.3
Git commit: 311b9ff0aa
Built: Sun Oct 29 15:42:02 2023
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: v1.7.11
GitCommit: 64b8a811b07ba6288238eefc14d898ee0b5b99ba.m
runc:
Version: 1.1.10
GitCommit:
docker-init:
Version: 0.19.0
GitCommit: de40ad0
[mason@mason-surfarch ~]$ uname -a
Linux mason-surfarch 6.6.6-arch1-1-surface #1 SMP PREEMPT_DYNAMIC Wed, 13 Dec 2023 21:27:25 +0000 x86_64 GNU/Linux
[mason@mason-surfarch ~]$

@merbekta
Copy link

The perfect solution 💕

Issue: Air is starting but not reloading on changes in the project

Solution: In .air.toml file add poll = true This is because Windows has some restrictions and to overcome that we set poll to true

Solution in code:

poll = true

it works for me

@swarajkumarsingh
Copy link

Polling is not a performant solution. What is the underlying issue here?

I have tested on Arch and Windows and both platforms suffer from the same issue.

[mason@mason-surfarch ~]$ docker version
Client:
Version: 24.0.7
API version: 1.43
Go version: go1.21.3
Git commit: afdd53b4e3
Built: Sun Oct 29 15:42:02 2023
OS/Arch: linux/amd64
Context: default

Server:
Engine:
Version: 24.0.7
API version: 1.43 (minimum version 1.12)
Go version: go1.21.3
Git commit: 311b9ff0aa
Built: Sun Oct 29 15:42:02 2023
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: v1.7.11
GitCommit: 64b8a811b07ba6288238eefc14d898ee0b5b99ba.m
runc:
Version: 1.1.10
GitCommit:
docker-init:
Version: 0.19.0
GitCommit: de40ad0
[mason@mason-surfarch ~]$ uname -a
Linux mason-surfarch 6.6.6-arch1-1-surface #1 SMP PREEMPT_DYNAMIC Wed, 13 Dec 2023 21:27:25 +0000 x86_64 GNU/Linux
[mason@mason-surfarch ~]$

Yes, polling is not the best option, but as long as we are only using air for development, it is acceptable. Air does not use additional memory, but it does make reloading somewhat slower, which is fine for development purposes. Perhaps this issue will be resolved later.

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

No branches or pull requests