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

[BUG] kill -TERM pid the process still exists #78

Closed
cielu opened this issue Feb 11, 2020 · 4 comments
Closed

[BUG] kill -TERM pid the process still exists #78

cielu opened this issue Feb 11, 2020 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@cielu
Copy link

cielu commented Feb 11, 2020

mac os .

image

I don't know if this is a bug .

The process could only kill by kill -9

@cielu cielu added the bug Something isn't working label Feb 11, 2020
@cielu cielu closed this as completed Feb 11, 2020
@hibiken
Copy link
Owner

hibiken commented Feb 11, 2020

@cielu Did you manage to resolve the issue?
You probably need to build the binary first instead of using go run .

@cielu
Copy link
Author

cielu commented Feb 12, 2020

@hibiken Thank you ! I have resolve the issue .

I know the reason about can't kill that process .

Asynq have own graceful shut down way , but the Gin framework don't

asynq :

	// Wait for a signal to terminate.
	sigs := make(chan os.Signal, 1)
	signal.Notify(sigs, syscall.SIGTERM, syscall.SIGINT, syscall.SIGTSTP)
	for {
		sig := <-sigs
		if sig == syscall.SIGTSTP {
			bg.processor.stop()
			bg.pinfo.SetState("stopped")
			continue
		}
		break
	}

so , if I want them work together , Gin should graceful shut down too (receive the signal to exit).

	// Init router
	router := routes.InitRouter()
	
	srv := &http.Server{
		Addr:    ":" + setting.AppCfg.AppPort,
		Handler: router,
	}
	/
	go func() {
		// service connections
		if err := srv.ListenAndServe(); err != nil && err != http.ErrServerClosed {
			log.Fatalf("listen: %s\n", err)
		}
	}()
	// Wait for interrupt signal to gracefully shutdown the server
	quit := make(chan os.Signal)
	// kill (no param) default send syscanll.SIGTERM
	// kill -2 is syscall.SIGINT
	// kill -9 is syscall. SIGKILL but can"t be catch, so don't need add it
	signal.Notify(quit, os.Interrupt)
	<-quit
	log.Println("Shutdown Server ...")
	// 
	ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
	defer cancel()
	// 
	if err := srv.Shutdown(ctx); err != nil {
		log.Fatal("Server Shutdown:", err)
	}
	log.Println("Server exiting")

But it is still recommend to separate the asynq workers

@hibiken
Copy link
Owner

hibiken commented Feb 12, 2020

Glad that you were able to resolve the issue.
Yes, intended use case for Asynq is to have its own worker binary separate from web server binary.

This was a useful feedback, maybe I can export Start and Stop methods for the Background to let the user of the library manually handle shutdown. I'll consider that if more users request it.

Thanks for creating the issues!

@cielu
Copy link
Author

cielu commented Feb 12, 2020

Haha,Look forward to version 1.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants