Skip to content
New issue

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

Return net.ErrClosed from Read methods when connection is closed by us #447

Open
srinivasan-getstan opened this issue Apr 15, 2024 · 6 comments

Comments

@srinivasan-getstan
Copy link

srinivasan-getstan commented Apr 15, 2024

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
Copy link
Contributor

nhooyr commented Apr 15, 2024

Use errors.Is

@nhooyr nhooyr closed this as completed Apr 15, 2024
@nhooyr
Copy link
Contributor

nhooyr commented Apr 15, 2024

Also not sure what you mean by server doesn't respond. And you're not using CloseRead correctly, please read the docs.

@nhooyr
Copy link
Contributor

nhooyr commented Apr 15, 2024

Actually this is interesting. You would expect net.ErrClosed instead. I'll make it return that.

@nhooyr nhooyr reopened this Apr 15, 2024
@nhooyr nhooyr changed the title failed to get reader: failed to read frame header: EOF Return net.ErrClosed from Read methods when connection is closed by us Apr 15, 2024
@srinivasan-getstan
Copy link
Author

Can you help me with how to implement CloseRead

@srinivasan-getstan
Copy link
Author

Actually this is interesting. You would expect net.ErrClosed instead. I'll make it return that.

Thanks

@srinivasan-getstan
Copy link
Author

srinivasan-getstan commented Apr 16, 2024

CloseSocketConnection

Can you point out what is wrong with the CloseSocketConnection function

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants