https://discord.cloudflare.com logo
Join Discord
Powered by
# workers-discussions
  • a

    avi

    03/28/2023, 11:57 PM
    no that's what i'm saying, it's the inverse of that
  • a

    avi

    03/28/2023, 11:58 PM
    to be clear:
  • a

    avi

    03/28/2023, 11:58 PM
    Copy code
    ts
    setInterval(() => console.log(Date.now(), 1000));
  • a

    avi

    03/28/2023, 11:58 PM
    in local, this always prints the same date
  • a

    avi

    03/28/2023, 11:58 PM
    (i.e., it's "nerfed")
  • a

    avi

    03/28/2023, 11:58 PM
    in dev and experimental-local, this prints a new date every time
  • k

    kian

    03/28/2023, 11:59 PM
    local's Spectre mitigations vs production's Spectre mitigations are just a discrepancy between the environments
  • k

    kian

    03/28/2023, 11:59 PM
    That isn't a 'real' 1000ms - it's 1000ms aligned with a 'fake' clock
  • k

    kian

    03/28/2023, 11:59 PM
    You can do
    Date.now()
    , do some hard compute that takes a few seconds,
    Date.now()
    and end up with a delta of 7ms - or 150ms - or 900ms - who knows, it varies
  • a

    avi

    03/28/2023, 11:59 PM
    ah, so you're saying that even when it's "working" (i.e. unfrozen), it's still fuzzed, with some delta
  • k

    kian

    03/29/2023, 12:00 AM
    Yeah - it's 'accurate' enough for vague timing, or rudimentary tracing, but never enough for you to use for a Spectre attack that requires repeated timing with sub-ms accuracy
  • a

    avi

    03/29/2023, 12:01 AM
    understood. i am 100% fine with that limitation, it shouldn't impact my use-case at all
  • a

    avi

    03/29/2023, 12:01 AM
    so, just to wrap things up then, the fact that
    Date.now()
    is completely frozen in
    --local
    — not just fuzzed, but literally unchanging EVER until the worker is restarted — is presumed to be a bug in the miniflare that
    local
    uses?
  • a

    avi

    03/29/2023, 12:02 AM
    fuzzing the time i completely understand, given Spectre. freezing i just don't get.
  • k

    kian

    03/29/2023, 12:03 AM
    current time in local only advances on external I/O - like reaching into cache, or making a fetch subrequest
  • k

    kian

    03/29/2023, 12:03 AM
    whereas current time in production advances on any async work really - like the
    scheduler.wait
    or
    interval
    stuff
  • k

    kian

    03/29/2023, 12:03 AM
    ref: https://github.com/cloudflare/miniflare/commit/a50b9687507d54055c5ec40963d2524280167116
  • k

    kian

    03/29/2023, 12:04 AM
    but yeah I'd consider that a discrepancy between
    local
    and the expected behaviour
  • k

    kian

    03/29/2023, 12:04 AM
    but I also have no documentation or references to guarantee that one day
    scheduler.wait(1)
    won't stop advancing the clock
  • a

    avi

    03/29/2023, 12:06 AM
    ahhhh
  • a

    avi

    03/29/2023, 12:07 AM
    super helpful. two quick things then
  • a

    avi

    03/29/2023, 12:07 AM
    1) i'm going to try doing some explicit disk I/O in the setInterval, to validate
  • a

    avi

    03/29/2023, 12:07 AM
    2) where do i pass
    --actual-time
    ? it's not recognized as a flag in
    wrangler dev
  • k

    kian

    03/29/2023, 12:08 AM
    It's a Miniflare only flag - and despite
    wrangler dev --local
    spawning Miniflare in the background, I don't think you can actually pass it w/ wrangler dev
  • k

    kian

    03/29/2023, 12:08 AM
    Someone might correct me on that, I've never used it
  • a

    avi

    03/29/2023, 12:11 AM
    ahhh
  • a

    avi

    03/29/2023, 12:12 AM
    can i not call
    fs.writeFileSync
    in a worker? just trying to 'force' I/O to test the theory
  • k

    kian

    03/29/2023, 12:12 AM
    fs
    is a Node module so nada
  • a

    avi

    03/29/2023, 12:13 AM
    mmm
  • k

    kian

    03/29/2023, 12:16 AM
    It depends what you're trying to test - a simple
    fetch("https://google.com")
    would update the time
1...236723682369...2509Latest