Bug Description
WriteMessageToSocket in pkg/gofr/context.go:90 panics with a nil pointer dereference when no WebSocket connection exists in the context.
Root Cause
Container.GetConnectionFromContext() can return nil when no WebSocket connection is associated with the current context, but the returned value is used directly without a nil check:
func (c *Context) WriteMessageToSocket(data any) error {
conn := c.Container.GetConnectionFromContext(c.Context)
message, err := serializeMessage(data)
if err != nil {
return err
}
return conn.WriteMessage(websocket.TextMessage, message) // PANIC if conn is nil
}
Bug Description
WriteMessageToSocketinpkg/gofr/context.go:90panics with a nil pointer dereference when no WebSocket connection exists in the context.Root Cause
Container.GetConnectionFromContext()can returnnilwhen no WebSocket connection is associated with the current context, but the returned value is used directly without a nil check: