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

Don't log connection closed exceptions as ERROR in websockets-next #40246

Merged
merged 1 commit into from
May 9, 2024

Conversation

geoand
Copy link
Contributor

@geoand geoand commented Apr 24, 2024

The clients can choose to close at any time, so it does not make sense to fill up logs with closed connection messages

@geoand geoand requested a review from mkouba April 24, 2024 12:32

This comment has been minimized.

Copy link
Contributor

@mkouba mkouba left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The clients can choose to close at any time, so it does not make sense to fill up logs with closed connection messages

I can't say that I agree with this proposal.

When a client closed a connection then the callback should not be called at all. If it is then it should only happen infrequently (when the connection is closed during processing or something like that). When exactly do you observe the logs filled with "closed connection" messages?

Also a user can define a global error handler to filter out these exceptions.

if (message == null) {
return false;
}
return message.contains("WebSocket is closed");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, this detection mechanism is too brittle. I know that there's no specific exception but this is not good at all.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The exception is a NoStackTraceException so there is nothing to go by.

I do agree it's brittle, but I don't see any alternative and having useless ERROR log entries is worse IMHO.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The exception is a NoStackTraceException so there is nothing to go by.

Yes, this is something we could report in Vertx maybe? One thing we could do is to also test the connection with WebSocketConnection.isClosed(), i.e. connections.isClosed() && message.contains("WebSocket is closed") .

I do agree it's brittle, but I don't see any alternative and having useless ERROR log entries is worse IMHO.

Well, the question is whether it's truly useless (some users might be interested in this) and as I pointed out the other question is how often does it actually happen?

We could also make this configurable, i.e. something like quarkus.websockets-next.server.log-closed-connection-errors with default value false 🤷.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, the question is whether it's truly useless (some users might be interested in this) and as I pointed out the other question is how often does it actually happen?

I easily made it happen in tests.

I also don't see why developers would need this in their logs, but let's see what @cescoffier thinks as well

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also don't see why developers would need this in their logs, but let's see what @cescoffier thinks as well

It's a signal that something went wrong on the server 🤷. Maybe we could use WARNING and no stack trace instead?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, I agree with @geoand that we should avoid logging connection errors that can be easily initiated by the client. I would even say that it could be seen as a potential security issue if you can easily fill the logs with stacktraces by disconnecting clients.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

even say that it could be seen as a potential security issue if you can easily fill the logs with stacktraces by disconnecting clients

Definitely.

Also, I am fairly sure we don't log these errors (or warnings) in our REST stack when the connection goes away before the response can be written

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that we should avoid logging connection errors that can be easily initiated by the client

Like I mentioned above this should only happen infrequently - when the connection is closed during processing of a message or something like that.

I would even say that it could be seen as a potential security issue if you can easily fill the logs with stacktraces by disconnecting clients.

I disagree. In that case, any server error would meet these conditions 🤔.

But like I mentioned in #40246 (comment) we should probably log a WARNING instead.

The only problem I can see is that the test relies on an exception message, which is super-brittle, may lead to false positives etc. We should at least combine (exception instanceof VertxException) && connections.isClosed() && message.contains("WebSocket is closed")

PS. I'm in the middle of a huge refactoring due to WebSocket client impl and I'm not going to merge any websocket-next PRs until the refactoring is finished 🤷.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I disagree. In that case, any server error would meet these conditions 🤔.

The differentiator is when the user can trigger at will. That is why in Quarkus REST we don't log anything by default.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I disagree. In that case, any server error would meet these conditions

It actually really depends on the conditions.
See for instance: GHSA-89h3-g746-xmwq

The only problem I can see is that the test relies on an exception message, which is super-brittle

That I agree. I would advise that we live with it (with your suggestion included if it works) until something in Vert.x allows us to do better (but we would need to create an issue there)?

@geoand geoand force-pushed the websockets-logging branch from 62cd218 to 3634485 Compare April 24, 2024 13:06

This comment has been minimized.

@geoand
Copy link
Contributor Author

geoand commented May 8, 2024

PR rebased

@geoand geoand force-pushed the websockets-logging branch from 3634485 to 1fe6806 Compare May 8, 2024 15:49

This comment has been minimized.

}

private static boolean isWebSocketIsClosedFailure(Throwable throwable) {
if (throwable == null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we add a check that WebSocketConnectionBase#isClosed() returns true?

I wonder if we should create a Vertx issue to introduce ConnectionClosedException or something like that...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we add a check that WebSocketConnectionBase#isClosed() returns true?

Done

I wonder if we should create a Vertx issue to introduce ConnectionClosedException or something like that.

@vietj would you be willing to have that in Vertx?

The clients can choose to close at any time, so it does not make
sense to fill up logs with closed connection messages
@geoand geoand force-pushed the websockets-logging branch from 1fe6806 to 56727a5 Compare May 9, 2024 14:00
Copy link

quarkus-bot bot commented May 9, 2024

Status for workflow Quarkus CI

This is the status report for running Quarkus CI on commit 56727a5.

✅ The latest workflow run for the pull request has completed successfully.

It should be safe to merge provided you have a look at the other checks in the summary.

You can consult the Develocity build scans.

@mkouba mkouba merged commit 81164b1 into quarkusio:main May 9, 2024
19 checks passed
@quarkus-bot quarkus-bot bot added this to the 3.11 - main milestone May 9, 2024
@geoand geoand deleted the websockets-logging branch May 9, 2024 14:24
@gsmet
Copy link
Member

gsmet commented May 10, 2024

If we want this in 3.10, we will need a specific backport as this class has been refactored in 3.11 AFAICS.

@geoand
Copy link
Contributor Author

geoand commented May 10, 2024

I can do that on Monday

@geoand
Copy link
Contributor Author

geoand commented May 13, 2024

#40582

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

Successfully merging this pull request may close these issues.

3 participants