Skip to content
This repository has been archived by the owner on May 24, 2023. It is now read-only.

connect close fail without error #81

Open
luyouxin84 opened this issue Dec 28, 2021 · 1 comment
Open

connect close fail without error #81

luyouxin84 opened this issue Dec 28, 2021 · 1 comment
Labels
🤔 Question Further information is requested 💭 Under Consideration

Comments

@luyouxin84
Copy link

Fiber version
"github.com/gofiber/fiber/v2"
"github.com/gofiber/websocket/v2"

Issue description
c := *websocket.Conn
c.Close() do not close connect and has not error return

Code snippet

app.Get("/ws", websocket.New(func(c *websocket.Conn) {
		// When the function returns, unregister the client and close the connection
		defer func() {
			unregister <- c
			c.Close()
		}()
		register <- c
		for {
			messageType, message, err := c.ReadMessage()
			if err != nil {
				if websocket.IsUnexpectedCloseError(err, websocket.CloseGoingAway, websocket.CloseAbnormalClosure) {
					log.Println("read error:", err)
				}

				return // Calls the deferred function, i.e. closes the connection on error
			}

			if messageType == websocket.TextMessage {
				// Broadcast the received message
				broadcast <- string(message)
			} else {
				log.Println("websocket message received of type", messageType)
			}
		}
	}))

this is code from your example: https://github.com/gofiber/recipes/blob/master/websocket-chat/main.go..
u can call c.Close() immediately but websocket still alive

@ReneWerner87
Copy link
Member

ReneWerner87 commented Dec 28, 2021

initial post in the wrong repository gofiber/fiber#1668

outcome in gofiber/fiber#1668 (comment)

@ReneWerner87 ReneWerner87 added ☢️ Bug Something isn't working 🤔 Question Further information is requested 💭 Under Consideration and removed ☢️ Bug Something isn't working labels Dec 28, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🤔 Question Further information is requested 💭 Under Consideration
Projects
None yet
Development

No branches or pull requests

2 participants