Skip to content

Unable to terminate the program by sending a TERM signal to the main process #89

@bourne-3

Description

@bourne-3

Context: I am using the Gin framework and have made some customizations to the framework. Here are some of the encapsulated structures.

type sm struct {
	*gin.Engine
	Server     *http.Server
	RouterFunc func(*gin.Engine)
	Config     WbConf
	Ln net.Listener
}

After completing all the initialization, the service is started using the following code:

func (ss *simpleServer) ListenAndServe() {
	if ss.Ln != nil {
		if err := ss.Engine.RunListener(ss.Ln); err != nil {
			fmt.Println("current listen err:", err)
			if !strings.Contains(err.Error(), "use of closed network connection") {
				logrus.WithError(err).Panic("InitServerStart() Mainserver ListenAndServe failed")
			}
		}
		return
	}

	ss.Server.Handler = ss.Engine
	if err := ss.Server.ListenAndServe(); err != nil {
		fmt.Println("current listen err:", err)
		if err != http.ErrServerClosed {
			logrus.WithError(err).Panic("InitServerStart() Mainserver ListenAndServe failed")
		}
	}
}

When using "overseer," I assign state.Listener to ss.Ln and then call ss.Engine.RunListener(ss.Ln) to start the service.

Problem: Currently, graceful restart is working fine. However, when I send a TERM signal to the program for a normal shutdown, it gets blocked and doesn't terminate.

image --- image

How can I resolve the above issues?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions