Skip to content

Conversation

0xbad0c0d3
Copy link
Contributor

@0xbad0c0d3 0xbad0c0d3 commented Sep 5, 2025

fixes #17514
P.S.: It would be better to avoid "side effects" of instrumentation process. But it will require more changes and deeply tested.

@0xbad0c0d3 0xbad0c0d3 changed the title DRAFT: Introduce lock instrumentation for context.waitUntil Introduce lock instrumentation for context.waitUntil to prevent multiple instrumentation Sep 5, 2025
cod1k added 7 commits September 8, 2025 12:16
Added `kFlushLock` to implement and manage a reusable `FlushLock` for the execution context. Enhanced promise handling with `Promise.withResolvers` and introduced type declarations for better developer experience.
Corrected the variable name from `prmise` to `promise` in the mock `waitUntil` function. Added a `props` property to `mockExecutionContext` for enhanced test completeness.
Refactored `getInstrumentedLock` and `storeInstrumentedLock` to use type-safe access via `Lockable` type and direct property manipulation. Removed unnecessary `Object.defineProperty` usage for better readability and maintainability.
Replaced custom delayed `waitUntil` implementations with `Promise.withResolvers` for improved readability and consistency. Removed unnecessary timer usage and adjusted test logic for better maintainability.
Introduced a new test case to validate that `makeFlushLock` does not wrap the execution context more than once. Ensures consistency and prevents potential redundancy in the flush handling logic.
Introduced the `cloneExecutionContext` utility to create shallow copies of the execution context while maintaining proper binding of key methods like `waitUntil` and `passThroughOnException`. Updated all handler proxies to use the cloned execution context, ensuring consistent behavior and preventing unintended side effects.
Introduced a new utility function `createPromiseResolver` to handle promise creation alongside external resolvers. Updated all references of `Promise.withResolvers` in the codebase and tests to use the new utility, ensuring compatibility and maintaining consistency.
cursor[bot]

This comment was marked as outdated.

@s1gr1d s1gr1d requested a review from AbhiPrasad September 8, 2025 15:22
Renamed `cloneExecutionContext` to `copyExecutionContext` and updated its implementation for improved binding logic and symbol handling. Moved `makeFlushLock` to `utils/flushLock` and adjusted imports accordingly. Added tests to validate `copyExecutionContext` behaviors and ensure robustness.
Improved the `copyExecutionContext` utility to prevent re-binding of already bound methods using a proxy. Updated test cases to validate this behavior and added support for `DurableObjectState` as a compatible context type.
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.

@sentry/cloudflare crashes DurableObjects due to unsafe & unnecessary proxying of waitUntil()
2 participants