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

fix: Prevent duplicate processes when multiple buildRuns run simultaneously #457

Merged
merged 3 commits into from
Oct 10, 2023

Conversation

toga4
Copy link
Contributor

@toga4 toga4 commented Aug 27, 2023

Hi maintainers, this PR fixes the behavior that air duplicates processses when multiple buildRuns run simultaneously.
Closes #404, Closes #421, Closes #426.

To reproduce issue:

main.go

package main

import (
	"log"
	"net/http"
	"os"
)

func main() {
	http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
		w.Write([]byte("Hello World!"))
	})

	log.Print(os.Getpid(), " Starting server...")
	if err := http.ListenAndServe(":8080", nil); err != nil {
		log.Fatal(os.Getpid(), err)
	}
}

Run air -d and save a file multiple times in a short period of time, then air executes multiple processes.
air

This behavior appears from v1.41.0, and seems to be brought by the following pull request.

I looked into what was making the difference, and it seems that the following code that was in place before the change was important.
https://github.com/cosmtrek/air/blob/d0a697adcf852559ab6fff59aa164b18f62571a0/runner/engine.go#L486-L490

This PR revive that code, and makes

  • killFunc is always resumed by binStopCh close.
  • killCh is for break rerun loop only.
  • handle exitCh after rerun loop breaks.

@toga4 toga4 changed the title stop other bin process when start bin fix: Prevent duplicate processes when multiple buildRuns run simultaneously Aug 27, 2023
@toga4 toga4 marked this pull request as ready for review August 27, 2023 13:50
@toga4
Copy link
Contributor Author

toga4 commented Aug 30, 2023

Confirmed this change works as expected (on M1 Mac).
image

@toga4
Copy link
Contributor Author

toga4 commented Aug 30, 2023

Hi, @cosmtrek @xiantang
Is there any chance you could review this PR? I'd appreciate your feedback.

@suntong
Copy link

suntong commented Sep 7, 2023

Hope the PR can be merged soon @cosmtrek @xiantang. thx!

@xiantang xiantang self-requested a review October 9, 2023 17:00
Copy link
Collaborator

@xiantang xiantang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM totally

@xiantang
Copy link
Collaborator

I know the root cause now, it's because when you save your code in a short period of time, air will start duplicate processes, but doesn't have any lock for it.
thank you good catch bug

@xiantang xiantang merged commit b5ef265 into air-verse:master Oct 10, 2023
2 checks passed
@toga4 toga4 deleted the fix-process-duplicate branch October 10, 2023 09:15
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

Successfully merging this pull request may close these issues.

Duplicate process after reload address already in use run multiple cmd one live reload
3 participants