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

js: Fix context usage with sub.Fetch #838

Merged
merged 1 commit into from
Oct 5, 2021
Merged

js: Fix context usage with sub.Fetch #838

merged 1 commit into from
Oct 5, 2021

Conversation

wallyqs
Copy link
Member

@wallyqs wallyqs commented Oct 5, 2021

The deadline of a context is now used to calculate the time used for expires instead of the default ttl of the JetStream context which was 5s by default. This was preventing library users from passing a context with a custom timeout.

This also disallows the usage of context.Background to make it explicit that sub.Fetch has to be used with a context that has a timeout since each fetch request has to include an expire time anyway.

In case context.WithCancel is used, then a child context with the same duration as the JetStream context default timeout will be created.

It is also updated to prevent using both timeout and context options with msg.InProgress(), msg.AckSync().

Fixes #834 #833

Signed-off-by: Waldemar Quevedo wally@synadia.com

@wallyqs wallyqs requested a review from kozlovic October 5, 2021 18:56
@coveralls
Copy link

coveralls commented Oct 5, 2021

Coverage Status

Coverage increased (+0.2%) to 87.366% when pulling 8f86c1d on js-ctx-fixes into 4a0ad2a on main.

Copy link
Member

@kozlovic kozlovic left a comment

Choose a reason for hiding this comment

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

Would recommend a little bit of refactor and more depending on answer to question regarding user-given context without deadline.

js.go Outdated Show resolved Hide resolved
js.go Show resolved Hide resolved
The deadline of a context is now used to calculate
the time used for `expires` instead of the default `ttl`
of the JetStream context which was 5s.  This was preventing
library users from passing a context with a custom timeout.

This also disallows the usage of `context.Background`
to make it explicit that `sub.Fetch` has to be used
with a context that has a timeout since each fetch
request has to include an expire time anyway.

In case `context.WithCancel` is used, then a child context
with the same duration as the JetStream context default
timeout will be created.

Also in case msg.Ack it was possible to pass both timeout
and a context which would have been ambiguous and only
context option being used.

Signed-off-by: Waldemar Quevedo <wally@synadia.com>
Copy link
Member

@kozlovic kozlovic left a comment

Choose a reason for hiding this comment

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

LGTM

@wallyqs wallyqs merged commit 8c2b0bf into main Oct 5, 2021
@wallyqs wallyqs deleted the js-ctx-fixes branch October 5, 2021 21:09
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.

Fetch ignores context timeout.
3 participants