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

Do not block by default #8580

Merged

Conversation

artembilan
Copy link
Member

Currently, many timeouts in the project are like -1 or other negative value with a meaning to wait indefinitely.

According to distributed systems design and bad demo developing experience it is not OK to block forever.

  • Rework most of the timeouts in the framework to be 30 seconds. Only one remained as 1 seconds is a PollingConsumer where it is better to not block even for those 30 seconds when no messages in the queue, but let the polling task be rescheduled.
  • Remove the MessagingGatewaySupport.replyTimeout propagation down to the PollingConsumer correlator where it was a -1 before and blocked the polling thread on the Queue.poll().
    This fixed the problem with a single thread in a pool for auto-configured TaskScheduler. Now with 1 seconds wait time we are able to switch to other scheduled tasks even with only 1 thread in the pool

Currently, many timeouts in the project are like `-1` or other negative value
with a meaning to wait indefinitely.

According to distributed systems design and bad demo developing experience
it is not OK to block forever.

* Rework most of the timeouts in the framework to be `30` seconds.
Only one remained as `1` seconds is a `PollingConsumer` where it is
better to not block even for those 30 seconds when no messages in the queue,
but let the polling task be rescheduled.
* Remove the `MessagingGatewaySupport.replyTimeout` propagation down to the
`PollingConsumer` correlator where it was a `-1` before and blocked
the polling thread on the `Queue.poll()`.
This fixed the problem with a single thread in a pool for auto-configured `TaskScheduler`.
Now with 1 seconds wait time we are able to switch to other scheduled tasks
even with only 1 thread in the pool
Long timeout = requestTimeout.getValue(Long.class);
if (timeout != null) {
gateway.setRequestTimeout(timeout);
if (requestTimeout != null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

We still need a null check here and use the default; GenericMessagingTemplate has -1 as its default.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure! See MessagingGatewaySupport:

private long replyTimeout = IntegrationContextUtils.DEFAULT_TIMEOUT;
...
template.setReceiveTimeout(this.replyTimeout);

So, if we don't call setReplyTimeout(), then that default value is used in the GenericMessagingTemplate.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah - ok.

if (requestTimeout == null || gatewayAnnotation.requestTimeout() != Long.MIN_VALUE) {
if (requestTimeout == null ||
gatewayAnnotation.requestTimeout() != IntegrationContextUtils.DEFAULT_TIMEOUT) {

requestTimeout = new ValueExpression<>(gatewayAnnotation.requestTimeout());
}
Copy link
Contributor

Choose a reason for hiding this comment

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

See comment in timeouts().

@garyrussell garyrussell merged commit 1bec420 into spring-projects:main Mar 21, 2023
@artembilan
Copy link
Member Author

fmbenhassine added a commit to spring-projects/spring-batch that referenced this pull request Jul 6, 2023

Verified

This commit was signed with the committer’s verified signature.
fmbenhassine Mahmoud Ben Hassine
The default value of sendTimeout in MessagingTemplate
was changed from -1 to 30000 in SI 6.1

Related to spring-projects/spring-integration#8580
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants