Skip to content

[4.4] Fix handling of sub-ms transaction timeouts #1034

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

Merged
merged 5 commits into from
Apr 11, 2024

Conversation

robsdedude
Copy link
Member

Transaction timeouts are specified in seconds as float. However, the server expects it in milliseconds as int. This would lead to

  1. rounding issues: previously, the driver would multiply by 1000 and
    then truncate to int. E.g., 256.4 seconds would be turned into 256399 ms
    because of float imprecision.
    Therefore, the built-in round is now used instead.
  2. values below 1 ms (e.g., 0.0001) would be rounded down to 0. However, 0 is
    a special value that instructs the server to not apply any timeout. This
    is likely to surprise the user which specified a non-zero timeout. In this
    special case, the driver now rounds up to 1 ms.

Back-port of: #940

Transaction timeouts are specified in seconds as float.
However, the server expects it in milliseconds as int. This would lead to

 1) rounding issues: previously, the driver would multiply by 1000 and
    then truncate to int. E.g., 256.4 seconds would be turned into 256399 ms
    because of float imprecision.
    Therefore, the built-in `round` is now used instead.
 2) values below 1 ms (e.g., 0.0001) would be rounded down to 0. However, 0 is
    a special value that instructs the server to not apply any timeout. This
    is likely to surprise the user which specified a non-zero timeout. In this
    special case, the driver now rounds up to 1 ms.

Back-port of: neo4j#940
Copy link

@AndyHeap-NeoTech AndyHeap-NeoTech left a comment

Choose a reason for hiding this comment

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

Just one question. Looks good though.

For better backwards compatibility, we're sending negative timeouts to the
DBMS as the 4.4 driver did before (even though those values might not have the
intuitive effect, we don't want to change the behavior of the driver too much in
a patch release).
@robsdedude robsdedude enabled auto-merge (squash) April 11, 2024 13:49
@robsdedude robsdedude merged commit ba18132 into neo4j:4.4 Apr 11, 2024
12 checks passed
@robsdedude robsdedude deleted the fix-tx-timeout-rounding-4.4 branch April 11, 2024 15:15
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