Skip to content

EOF returned instead of real error when connecting with websockets and an expired jwt token #2024

@mxmauro

Description

@mxmauro

Observed behavior

As the title says, when I call nats.Connect using an expired (or about to) JWT token, the function returns EOF instead of nats.ErrAuthorization or nats.ErrAuthExpired

I did a traffic analysis with WireShark and I can see the server INFO and also the -ERR 'Authorization Violation' message.

I can also see the websocket close frame the server sends with Authentication Failure and the client response.

The issue happens in Conn.sendConnect. connectProto and writeDirect calls succeedes but the nc.readProto call fails with EOF because, at the time it executes, the connection is closed, and the -ERR message was also consumed in the natsReader object (off == -1 and you can see the message still in the buffer array)

If there is a way to get the close frame reason, I don't know.

Expected behavior

To return the proper error.

Server and client version

Client: 1.48.0

Host environment

Client: Microsoft Windows
Server: AWS Linux

Steps to reproduce

Just connect to a server with a valid but expired token using websocket protocol.

Metadata

Metadata

Assignees

No one assigned

    Labels

    defectSuspected defect such as a bug or regression

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions