gin-gonic / gin

Gin is a HTTP web framework written in Go (Golang). It features a Martini-like API with much better performance -- up to 40 times faster. If you need smashing performance, get yourself some Gin.
https://gin-gonic.com/
MIT License
78.93k stars 8.02k forks source link

Socket file that gin listened are not removed when stopping gin process #3817

Open howcrazy opened 10 months ago

howcrazy commented 10 months ago

Description

When listen to unix socket, socket file are not removed when stopping gin process (use Ctrl + C). The next time it is executed, the process will report an error: [GIN-debug] [ERROR] listen unix /tmp/testgin.sock: bind: address already in use

How to reproduce

package main

import (
    "github.com/gin-gonic/gin"
    "net/http"
)

func main() {
    r := gin.Default()
    r.GET("/ping", func(c *gin.Context) {
        c.JSON(http.StatusOK, gin.H{
            "message": "pong",
        })
    })
    file := "/tmp/testgin.sock"
    //os.Remove(file)
    r.RunUnix(file)
}

Environment

ismdeep commented 10 months ago

2280

howcrazy commented 10 months ago

The socket should instead be cleaned up at shutdown.

It creates the sock file but does not delete it after Ctrl + C or stop by supervisord. defer os.Remove(file) not executed.

Maybe I should handle this situation manually?

openarun commented 9 months ago

+1

daftaupe commented 7 months ago

The socket should instead be cleaned up at shutdown.

It creates the sock file but does not delete it after Ctrl + C or stop by supervisord. defer os.Remove(file) not executed.

Maybe I should handle this situation manually?

I don't think you should have to, if the service is not running anymore, the socket should disappear imo.

howcrazy commented 7 months ago

The socket should instead be cleaned up at shutdown.

It creates the sock file but does not delete it after Ctrl + C or stop by supervisord. defer os.Remove(file) not executed. Maybe I should handle this situation manually?

I don't think you should have to, if the service is not running anymore, the socket should disappear imo.

But it still there 😂