Skip to content

Issue #13043 - review of websocket Flushers for 12.1 #13250

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

Open
wants to merge 2 commits into
base: jetty-12.1.x
Choose a base branch
from

Conversation

lachlan-roberts
Copy link
Contributor

closes #13043

  • rename TransformingFlusher to WebSocketFlusher and update it to use an OutgoingEntry API instead of frame + callback + batch.
  • add method to override to handle onCompleteFailure on WebSocketFlusher
  • WebSocketFlusher now wraps the callback needed to continue processing in the OutgoingEntry itself.
  • Rename DemandingFlusher to WebSocketDemander, and use a lock instead of multiple atomic variables for the implementation.

@lachlan-roberts lachlan-roberts requested review from gregw and sbordet June 18, 2025 04:23
@lachlan-roberts lachlan-roberts self-assigned this Jun 18, 2025
@joakime joakime linked an issue Jun 18, 2025 that may be closed by this pull request
@sbordet sbordet moved this to 👀 In review in Jetty 12.1.0 Jun 18, 2025
Copy link
Contributor

@gregw gregw left a comment

Choose a reason for hiding this comment

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

Mostly looks good, but I think some comments are wrong with their upstream/downstream usage? which way the stream flows needs to be made clear in comments.

Then I'm not sure mixing in "Next" is a good idea. Isn't that just "Downstream"?

Comment on lines +47 to +48
private boolean _upstreamDemand = false;
private boolean _downstreamDemand = false;
Copy link
Contributor

Choose a reason for hiding this comment

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

probably a little comment to clarify which direction upstream and downstream are.

{
_emitFrame = emitFrame;
}

@Override
public void setNextDemand(DemandChain nextDemand)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should "Next" be "downstream"? Or if next/prev makes sense, then use them instead of upstream/downstream ?

}

/**
* This is used by the downstream layer to demand a new frame to be processed in {@link #handle(Frame, Callback, boolean)}.
Copy link
Contributor

Choose a reason for hiding this comment

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

Oh - I would have called the layer calling demand upstream, as it is the layer above.
Hmmmm maybe I suggested bad names for you???

Copy link
Contributor

Choose a reason for hiding this comment

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

I actually think you meant upstream

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 was thinking that the most upstream would be the WebSocketConnection as the source of the frames, and the most downstream would be the application demanding the frames. In which case this method would correspond to the downstream demand.

But if you think about the demand itself originating from the application then that would be the most upstream.

So I could just reverse all the naming of all my upstream/downstreams.

Copy link
Contributor

Choose a reason for hiding this comment

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

@lachlan-roberts Let me think... I could be confused myself...
In this case, data is flowing from the network to the application, so in one sense the "stream" is flowing from low layers down to the application, so the application calling demand would be "downstream" as you said in at least one of your comments.
But more typically (and chatGPT backs me here) upstream is towards a higher layer of the protocol stack, so the application and/or layer above calling demand is "upstream".

Needless to say, the most important thing is to be internally consistent, and I don't think you current comments are. Also you have used "Next" in at least once circumstance, which is a mixed metaphor.

So pick a pair: upstream/downstream; downstream/upstream; prev/next; above/below; etc. and then explain the metaphor in the opening comments apply it rigorously to all code and comments

Copy link
Contributor

Choose a reason for hiding this comment

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

Demandee/demandor?

Source/Consumer?

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 fact that we need to have this discussion probably means the names aren't suitable and are likely to cause some confusion.

I can try using producerDemand and consumerDemand names.

Also you have used "Next" in at least once circumstance

This is a pre-existing method on the DemandChain interface. But it would be a little confusing to rename this to setProducerDemand() when there is no concept of consumer demand on the interface.

Comment on lines +153 to +154
// Fulfill the incoming demand to receive a new frame.
_upstreamDemand = false;
Copy link
Contributor

Choose a reason for hiding this comment

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

Oh the layer above is called upstream? Hmmmm is the comment to demand wrong?

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

Successfully merging this pull request may close these issues.

Review WebSocket flushers
2 participants