Open nuttert opened 4 months ago
@nuttert Can you post a full example ?
Handler:
import "github.com/gofiber/contrib/websocket"
type WSConnection = websocket.Conn
func (r *Router) WSHandler(c *WSConnection) {
id := strings.Clone(c.RemoteAddr().String())
c.EnableWriteCompression(true)
c.SetCompressionLevel(flate.BestSpeed + 1)
defer c.Close()
r.connections.Set(id, c)
// Publisher spawns a separate goroutine that receives messages from a channel,
// then on each message in the goroutine the callback is called
pub := r.setupPublisher(id, func(headerBytes, msg []byte) bool {
return r.writeMessage(c, msg, id)
})
...
// Read from the connection in the goroutine
}
Write message to the gofiber connection:
func (r *Router) writeMessage(c *WSConnection, msg []byte, id string) bool {
if c == nil {
log.Error().Msgf("Connection is not initialized %s", id)
return false
}
if len(msg) == 0 {
return false
}
if err := c.WriteMessage(websocket.TextMessage, msg); err != nil {
return false
}
return true
}
Listener:
app := fiber.New()
app.Use("/ws", func(c *fiber.Ctx) error {
if websocket.IsWebSocketUpgrade(c) {
c.Locals("allowed", true)
return c.Next()
}
return fiber.ErrUpgradeRequired
})
app.Get(*args.RouterWSPath, websocket.New(r.WSHandler, websocket.Config{
EnableCompression: true,
}))
Bug Description
I got the segfault, when I turned on a compression:
How to Reproduce
Steps to reproduce the behavior: Turn on the compression and after several hours(if you actively use the server) you will get a segfault
Expected Behavior
I expect that compression should work fine without segfaults
Contrib package Version
contrib/websocket v1.3.0
Code Snippet (optional)
Checklist: