Skip to content

GH-8678: Make Buffer Overflow Strategy Configurable in IntegrationWebSocketContainer #8679

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

Closed
wants to merge 2 commits into from

Conversation

ColoredCarrot
Copy link
Contributor

Implement #8678: Make the send buffer overflow strategy configurable in IntegrationWebSocketContainer.

Adds a simple setter that is the missing analogue to setSendTimeLimit and setSendBufferSizeLimit.

Copy link
Member

@artembilan artembilan left a comment

Choose a reason for hiding this comment

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

Thank you for the contribution.

A couple more comments to whatever I have already reviewed:

  1. Any chances to have a simple unit test to new property is propagated properly to the decorated WebSocketSession. We can verify that via TestWebSocketListener in the ClientWebSocketContainerTests.
  2. Add your name to the @author list of the affected classes.

@@ -67,6 +68,9 @@ public abstract class IntegrationWebSocketContainer implements DisposableBean {

public static final int DEFAULT_SEND_BUFFER_SIZE = 512 * 1024;

public static final ConcurrentWebSocketSessionDecorator.OverflowStrategy DEFAULT_SEND_BUFFER_OVERFLOW_STRATEGY =
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we need this extra property for a default value: we simply can initialize our sendBufferOverflowStrategy with that ConcurrentWebSocketSessionDecorator.OverflowStrategy.TERMINATE as default value.
Or better to have this as null and chose an appropriate ctor when we instantiate ConcurrentWebSocketSessionDecorator

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 considered the latter approach as well. I thought that having the default be explicit in this class, in addition to ConcurrentWebSocketSessionDecorator, would relieve users of having to open up ConcurrentWebSocketSessionDecorator to see the default.
We could mention that TERMINATE is the default in the Javadoc, but I feel like that would more than likely not get updated if the default is ever changed in ConcurrentWebSocketSessionDecorator. Thoughts?

Copy link
Member

Choose a reason for hiding this comment

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

Well, to have a single place of truth, I'd prefer a @see ConcurrentWebSocketSessionDecorator in our new setter for this strategy.
Right, user would need to look there for more info, but then we would not not to worry about breaking change ever.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fair enough, I'll get that implemented :)

* By default, the session associated with the culpable message is terminated.
*
* @param overflowStrategy The overflow strategy to use (see {@link ConcurrentWebSocketSessionDecorator.OverflowStrategy}).
*
Copy link
Member

Choose a reason for hiding this comment

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

@ColoredCarrot
Copy link
Contributor Author

Thank you for the detailed review & comments!

About the unit test: Unlike sendTimeLimit and bufferSizeLimit, ConcurrentWebSocketSessionDecorator's overflowStrategy has no getter (and is private). This seems like an oversight. Since ConcurrentWebSocketSessionDecorator isn't part of Spring Integration, we (probably?) can't fix that as part of this ticket.

In the meantime, the only way I can see to implement this test is by testing the actual behavior (I'm assuming using reflection to get the field value is out of the question). That would essentially duplicate this test case of Spring WebSocket.
Definitely possible; is that within the scope, or should we await the getter?

@artembilan
Copy link
Member

or should we await the getter?

No, we should not.

See the mentioned ClientWebSocketContainerTests and its TestWebSocketListener with an afterSessionStarted() impl.
That's where that ConcurrentWebSocketSessionDecorator is propagated.
To get access to that private ConcurrentWebSocketSessionDecorator.overflowStrategy property we just can use our TestUtils.getPropertyValue() API which indeed is based on reflection anyway, but much easier to use.

@ColoredCarrot
Copy link
Contributor Author

Right, I just wasn't aware that extracting private values like that was common practice. Won't be an issue then, thanks for the heads up.

Copy link
Member

@artembilan artembilan left a comment

Choose a reason for hiding this comment

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

I'm merging with with some refactoring to be able to back-port this down to 5.5.x where we cannot use record yet.

@artembilan
Copy link
Member

Merged as be53593.

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