gin icon indicating copy to clipboard operation
gin copied to clipboard

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

Open howcrazy opened this issue 1 year ago • 5 comments

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

  • go version: v1.20.3
  • gin version (or commit ref): v1.9.1
  • operating system: osx, ubuntu

howcrazy avatar Jan 03 '24 07:01 howcrazy

#2280

ismdeep avatar Jan 05 '24 09:01 ismdeep

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?

howcrazy avatar Jan 07 '24 14:01 howcrazy

+1

openarun avatar Feb 06 '24 21:02 openarun

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.

daftaupe avatar Mar 25 '24 16:03 daftaupe

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 😂

howcrazy avatar Apr 05 '24 06:04 howcrazy