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

ExpiryPolicy.eternal duration causes overflow when compiled to Javascript #7

Closed
ajrcarey opened this issue Apr 19, 2021 · 5 comments
Closed
Assignees
Labels
duplicate This issue or pull request already exists

Comments

@ajrcarey
Copy link

ajrcarey commented Apr 19, 2021

Describe the bug

ExpiryPolicy.eternal sets a duration that overflows Javascript's number type. This is specific to compiling to web.

To Reproduce
Steps to reproduce the behavior:

Nothing special required. Create a cache with Lfu eviction policy, and add any item to it. It'll work fine when running on the Dart VM, but throw an error when running in a web browser.

Expected behavior
Consistent behaviour on every platform.

Version
Dart SDK version: 2.12.2 (stable) (Wed Mar 17 10:30:20 2021 +0100) on "linux_x64"

Additional context
The problem can be fixed by reducing the value of the eternal constant in api/expiry/expiry_policy.dart:

abstract class ExpiryPolicy {
/// The value used to represent a eternal duration
static const Duration eternal = Duration(days: 999999);

...

It's presumably due to the difference in numeric precision between the Dart VM and Javascript, although that's just a guess; I didn't spend much time tracking it down other than the bare minimum necessary to fix my problem.

@ajrcarey
Copy link
Author

Sample of error thrown:

Error: Invalid argument(s): DateTime is outside valid range: 8.640000000161878e+22
at Object.throw_ [as throw] (http://localhost:36401/dart_sdk.js:5334:11)
at new core.DateTime._withValue (http://localhost:36401/dart_sdk.js:123247:17)
at core.DateTime.now.add (http://localhost:36401/dart_sdk.js:123139:14)
at default_cache.DefaultCache.new.[_putEntry] (http://localhost:36401/packages/stash/src/memory/memory_store.dart.lib.js:450:28)
at http://localhost:36401/packages/stash/src/memory/memory_store.dart.lib.js:511:33
at _RootZone.runUnary (http://localhost:36401/dart_sdk.js:38889:58)
at _FutureListener.then.handleValue (http://localhost:36401/dart_sdk.js:33875:29)
at handleValueCallback (http://localhost:36401/dart_sdk.js:34435:49)
at Function._propagateToListeners (http://localhost:36401/dart_sdk.js:34473:17)
at _Future.immediate.[_completeWithValue] (http://localhost:36401/dart_sdk.js:34315:23)
at async._AsyncCallbackEntry.new.callback (http://localhost:36401/dart_sdk.js:34338:35)
at Object._microtaskLoop (http://localhost:36401/dart_sdk.js:39176:13)
at _startMicrotaskLoop (http://localhost:36401/dart_sdk.js:39182:13)
at http://localhost:36401/dart_sdk.js:34689:9

@ajrcarey ajrcarey changed the title Eternal duration ExpiryPolicy.eternal duration causes overflow when compiled to Javascript Apr 19, 2021
@ajrcarey
Copy link
Author

Looks like it might be related to #5, I'm currently using package version 1.0.4.

@ivoleitao
Copy link
Owner

Yes, I've fixed this on the null version only. This is just the first problem there's a lot more as I haven't really tested this on dartjs before. It will be very hard to retrofit this as I had to fix a number of concurrency problems on the tests as well in order to have this fixed. Also I'm already moving to monorepo so the repo structure is completely changed. The best about this is that I will finally have a full encompassing CI process that will support dart js tests as well

@ivoleitao ivoleitao self-assigned this Apr 20, 2021
@ivoleitao ivoleitao added the wontfix This will not be worked on label Apr 20, 2021
@ivoleitao
Copy link
Owner

If you can move to the new published version (2.0.0-nullsafety.4) it would be ideal.

@ajrcarey
Copy link
Author

Will do, many thanks.

@ivoleitao ivoleitao added duplicate This issue or pull request already exists and removed wontfix This will not be worked on labels Apr 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants