Skip to content

Report errors on, or circumvent, multiple RefCell borrows in Deno ops #444

@andreaphylum

Description

@andreaphylum

Currently, Deno ops (i.e. our Rust-side API) require a Rc<RefCell<OpState>> parameter for handling state. All of our ops are asynchronous, and a user not awaiting on them immediately will cause the RefCell to be mutably borrowed multiple times, which will result in a panic:

Deno.core.print(JSON.stringify(await PhylumApi.get_user_info())) // this will not panic
Deno.core.print(JSON.stringify(PhylumApi.get_user_info())) // this will panic

We need to either leverage some concurrency primitive (e.g. Mutex/RwLock), and make sure it won't ever result in a deadlock, or provide the user with actionable feedback (e.g. "please immediately await Phylum API calls"). Allowing concurrency and favoring more async-friendly interior mutability structures in place of Rc<RefCell<T>> should in general be preferred, but Deno's documentation is currently not super clear on the mechanisms that could cleanly complement that.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or requestextensionsPhylum CLI extensionsmedium priorityShould be handled as soon as possible

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions