AGuyWhoIsBored
AGuyWhoIsBored
CDCloudflare Developers
Created by AGuyWhoIsBored on 12/11/2023 in #workers-help
Worker Receiving Request Very Late / Date.now() Incorrect?
I am sending requests to a CF Worker via GitHub Actions. For each of these requests sent via GitHub Actions, there is an expiry field in its JSON payload that is populated with Date.now() + 60000 (so the request expires 1 minute after it is created and sent). My CF Worker is set up such that if Date.now() > expiry, then the request is rejected. (this is for request signing, implemented very similarly to this example: https://developers.cloudflare.com/workers/examples/signing-requests/) Sporadically, I notice that the request is rejected via my CF worker due to it expiring, when it shouldn't have been rejected. Digging into it more, I notice that the CF Worker processes my request more than a minute later than it was sent via GitHub Actions, and I don't understand why. As an example, a particular request was sent at Mon, 11 Dec 2023 05:02:55 GMT from GitHub Actions to the CF Worker endpoint, but it was picked up by the CF Worker at Mon Dec 11 2023 05:04:05 GMT . This is seen from the "Real-Time Logs" feature within my CF Worker dashboard (and therefore the request is now expired). after debugging and sleuthing, the only leads so far I have for why this is happening are: 1. CF Workers takes over a minute to cold start and/or to start processing the request - this sounds incredibly unlikely ... 2. Something related to this: https://developers.cloudflare.com/workers/learning/security-model/#step-1-disallow-timers-and-multi-threading
In Workers, you can get the current time using the JavaScript Date API by calling Date.now(). However, the time value returned is not the current time. Date.now() returns the time of the last I/O. It does not advance during code execution.
I'm not sure where to go from here and I would appreciate any pointers! This functionality is essential for my app so I would love to have this intermittent behavior figured out 😄
2 replies