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

Closed
opened 2026-03-02 05:17:58 +03:00 by kerem · 4 comments
Owner

Originally created by @cielu on GitHub (Feb 11, 2020).
Original GitHub issue: https://github.com/hibiken/asynq/issues/78

Originally assigned to: @hibiken on GitHub.

mac os .

image

I don't know if this is a bug .

The process could only kill by kill -9

Originally created by @cielu on GitHub (Feb 11, 2020). Original GitHub issue: https://github.com/hibiken/asynq/issues/78 Originally assigned to: @hibiken on GitHub. mac os . ![image](https://user-images.githubusercontent.com/13715811/74228965-706eca80-4cfc-11ea-9048-0caf28dde476.png) I don't know if this is a bug . The process could only kill by kill -9
kerem 2026-03-02 05:17:58 +03:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@hibiken commented on GitHub (Feb 11, 2020):

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

<!-- gh-comment-id:584768287 --> @hibiken commented on GitHub (Feb 11, 2020): @cielu Did you manage to resolve the issue? You probably need to build the binary first instead of using `go run` .
Author
Owner

@cielu commented on GitHub (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

<!-- gh-comment-id:584992555 --> @cielu commented on GitHub (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 : ```go // 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). ```go // 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
Author
Owner

@hibiken commented on GitHub (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!

<!-- gh-comment-id:585051504 --> @hibiken commented on GitHub (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!
Author
Owner

@cielu commented on GitHub (Feb 12, 2020):

Haha,Look forward to version 1.0

<!-- gh-comment-id:585060919 --> @cielu commented on GitHub (Feb 12, 2020): Haha,Look forward to version 1.0
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/asynq#19
No description provided.