Skip to content

014 - Proposal to refactor frontend handler and centralize session context#88

Open
hrishabhg wants to merge 1 commit intokroxylicious:mainfrom
hrishabhg:014-frontend-handler-refactoring-and-centralised-session-context
Open

014 - Proposal to refactor frontend handler and centralize session context#88
hrishabhg wants to merge 1 commit intokroxylicious:mainfrom
hrishabhg:014-frontend-handler-refactoring-and-centralised-session-context

Conversation

@hrishabhg
Copy link

Refactor frontend handler architecture to improve separation of concerns, introduce a centralized session context, fix HAProxy message memory leak, and simplify the state machine by eliminating unnecessary states.

Refactor frontend handler architecture to improve separation of concerns, introduce a centralized session context, fix HAProxy message memory leak, and simplify the state machine by eliminating unnecessary states.

Signed-off-by: Hrishabh Gupta <hgupta@confluent.io>
@hrishabhg hrishabhg requested a review from a team as a code owner January 27, 2026 04:46
@hrishabhg hrishabhg marked this pull request as draft January 27, 2026 04:47
@hrishabhg hrishabhg marked this pull request as ready for review January 27, 2026 04:47
@hrishabhg hrishabhg changed the title Proposal to refactor frontend handler and centralize session context 014 - Proposal to refactor frontend handler and centralize session context Jan 27, 2026
Copy link
Member

@tombentley tombentley left a comment

Choose a reason for hiding this comment

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

This seems mostly reasonable. Thanks.

As a more general point, please don't feel the need to write a proposal for a refactoring which doesn't touch public APIs (which is the case here). A proposal can serve as a place to discuss a larger change without actually having to implement it in its entirety so you can open a PR for it.

I've also been thinking about a few other changes which would function as either clean up of accumulated tech debt (which we should do anyway) or enablers for routing-like functionality:

  • Currently we initialize the backend pipeline in the frontend handler. That seems ripe for moving to the backend handler itself. I hope to open a PR for this next week.
  • I think we should be able to factor out some kind of abstraction for tracking reasons and managing the autoRead flag which we use for backpressure. I hope to open a PR for this next week.
  • I don't think the PCSM can really survive in its current form if we want to support routing. It seems to me there's a state machine associated with the frontend (tracking the building up of your ClientSession), and one associated with a backend. A router could only forward (most) requests to a backend once we have TCP, TLS?, SASL?. At that point the Route is in the FORWARDING state, and requests can pass down the pipeline associated with that Route. Does this fit whatever thoughts you might have had about routing?

Comment on lines +18 to +20
### HAProxy message memory leak

`HAProxyMessage` implements Netty's `ReferenceCounted` interface but is never released. The message is intercepted in `HAProxyMessageHandler`, passed to the state machine, stored in state records, but never has `release()` called. This causes a memory leak.
Copy link
Member

Choose a reason for hiding this comment

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

This seems like low-hanging fruit which doesn't depend on the rest. We should just fix it. Would you be willing to open a PR for this?

Copy link
Author

Choose a reason for hiding this comment

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

I will take that up soon with the HAProxyMessage fix.

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.

2 participants