-
Notifications
You must be signed in to change notification settings - Fork 148
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
Fix ArithmeticException in toJavaDuration. #1950
Conversation
|
One thing I called out in the issue, but may not have mentioned is we should maintain the precision of the conversion.
changing the conversion precision might subtly break users tests using the time skipping test server. |
For the CI failure you just need to rebase |
I am not sure this change is backwards compatible. While I understand the reasoning for preventing overflow, the loss of precision I think is intentional or at least safe. No use of proto duration by the Java SDK or the Temporal server is expected to be more precise than the millisecond level.
if (Workflow.getInfo().getWorkflowRunTimeout().toMillis() > 1000) {
myActivities.doThing();
} This PR changes that conditional I think. Now, I admit this is a contrived example and I'm not that worried about this incompatibility, but it should be known. I think we should stick with millisecond precision for all Temporal duration use (this doesn't apply to users' use of protos correct?). Can we just protect against overflow (convert to max long?) but otherwise leave the code as is? |
Whoops, I overlooked that. Fixed. |
I'm now doing the rounding myself. Any use of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To confirm, with the current changes, the behavior is exactly as it is today for normal positive durations that don't overflow and only handles overflow but not the loss of precision? The PR title could be confusing if we removed the fix-loss-of-precision requirement, which is fine.
May want a test or two.
temporal-sdk/src/main/java/io/temporal/internal/common/ProtobufTimeUtils.java
Outdated
Show resolved
Hide resolved
temporal-sdk/src/main/java/io/temporal/internal/common/ProtobufTimeUtils.java
Outdated
Show resolved
Hide resolved
temporal-sdk/src/main/java/io/temporal/internal/common/ProtobufTimeUtils.java
Outdated
Show resolved
Hide resolved
77b21f4
to
81179a0
Compare
public class ProtobufTimeUtilsTest { | ||
|
||
@Parameters | ||
public static Collection<Object[]> data() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we confirm all the tests that didn't throw have the same behaviour before and after your change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I specifically tested that in the first commit after the rebase + force-push. Commit c7854d1e641e contains no changes to the logic (just the Objects.isNull
cosmetic change) and passes all tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Happily, the belief that Durations.toMillis
does round to nearest instead of truncation was mistaken, as that would have meant that there was an asymmetry in the conversion. Both Duration.toMillis
(Java) and Durations.toMillis
(protobuf) truncate.
It now has tests and I've retitled the pull request + interactive rebased the commit messages to better reflect what's going on. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, first commit 🎉
This turns out to be factually false, but the documentation is confusingly worded. The |
Fixes #1938 aka SDK-1319.
What was changed
Eliminate risk of ArithmeticException due to
long
overflow intoJavaDuration
.Why?
Make the API exception-safe for extreme duration values, especially for values which are legal in the protobuf wire format but not for Java's
Duration
type.Checklist
Closes GitHub Issue #1938.
How was this tested: created new tests in temporal-sdk module that captured existing behavior with small values to prove that the visible behavior was unchanged for already-legal values.