Return net.ErrClosed from Read methods when connection is closed by us
srinivasan-getstan opened this issue · 6 comments
srinivasan-getstan commented
Whenever I close the connection I get this error and the server doesn't respond. Can you please help me here
My reader function;
func WsReader(log *logger.LoggerEvent, requestCtx context.Context, wsConn *_websocket.Conn, requestId uuid.UUID, userId int32) {
for {
_, buff, err := wsConn.Read(requestCtx)
if err != nil {
if err != io.EOF {
log.Errorf(`Failed to read the data : ERROR : %s : CODE : %s`, err, _websocket.CloseStatus(err))
}
break
}
if len(buff) == 0 {
break
}
data := eventSchemaHandler.GetRootAsEventWrapper(buff, 0)
log.Infof("Event received : %s : USER_ID : %d", data.Event(), userId)
unionTable := new(flatbuffers.Table)
data.Payload(unionTable)
event.SerializeEvents(log, wsConn, unionTable, requestId, string(data.Event()), string(data.ClubId()))
}
}
My Connection Close function:
func CloseSocketConnection(wsConn *_websocket.Conn, clubId string, statusCode _websocket.StatusCode, msg string) {
wsConn.CloseRead(context.Background())
wsConn.Close(statusCode, msg)
}
nhooyr commented
Use errors.Is
nhooyr commented
Also not sure what you mean by server doesn't respond. And you're not using CloseRead correctly, please read the docs.
nhooyr commented
Actually this is interesting. You would expect net.ErrClosed instead. I'll make it return that.
srinivasan-getstan commented
Can you help me with how to implement CloseRead
srinivasan-getstan commented
Actually this is interesting. You would expect net.ErrClosed instead. I'll make it return that.
Thanks
srinivasan-getstan commented
CloseSocketConnection
Can you point out what is wrong with the CloseSocketConnection function