We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I want to close a websocket connection but nothing happens (no error etc.). The client remains connected and can also send messages.
Steps to reproduce the behavior:
The server should close the connection after 5 seconds
websocket/v1.1.0
package main import ( "log" "time" "github.com/gofiber/contrib/websocket" "github.com/gofiber/fiber/v2" ) func main() { app := fiber.New() app.Use("/ws", middleware) app.Get("/ws", websocket.New(handler)) log.Fatal(app.Listen(":8080")) } func middleware(c *fiber.Ctx) error { if websocket.IsWebSocketUpgrade(c) { return c.Next() } return fiber.ErrUpgradeRequired } func handler(conn *websocket.Conn) { go func() { time.Sleep(5 * time.Second) if err := conn.Close(); err != nil { log.Fatal(err) } }() for { _, msg, err := conn.ReadMessage() if err != nil { log.Println(err) return } log.Printf("msg: %s", msg) } }
The text was updated successfully, but these errors were encountered:
@mstrYoda Any idea what may be causing this?
Sorry, something went wrong.
Hi, you can not close a hijacked connection in this way. It is basically do nothings.
You can just return from the websocket handler function and it closes underlying connection after exiting handler.
Returning directly from the websocket handler worked. But for what purpose is the (*websocket.Conn).Close() func if it can't close the connection?
No branches or pull requests
Bug Description
I want to close a websocket connection but nothing happens (no error etc.).
The client remains connected and can also send messages.
How to Reproduce
Steps to reproduce the behavior:
Expected Behavior
The server should close the connection after 5 seconds
Contrib package Version
websocket/v1.1.0
Code Snippet (optional)
Checklist:
The text was updated successfully, but these errors were encountered: