🧪 Announcing PicJS: TypeScript/JavaScript support for PocketIC!

Thanks a lot for reporting! I believe this bug has been fixed by this commit - note the sentence “This PR also fixes a bug when deleting an instance: an instance should not be deleted if it is still busy with a computation.” in the PR description.

Let me try to provide more context on the bug: while an operation (e.g., a request you submitted using pic-js) is running on a PocketIC instance, the instance state is “Busy”. Before the above commit, deleting an instance would unconditionally replace its state with “Deleted”:

            let mut instance = instances[instance_id].lock().await;
            match std::mem::replace(&mut instance.state, InstanceState::Deleted) {
                InstanceState::Available(pocket_ic) => {
                    std::mem::drop(pocket_ic);
                    break;
                }
                InstanceState::Deleted => {
                    break;
                }
                InstanceState::Busy { .. } => {}
            }

and then once the running operation finishes, the instance state is already “Deleted” instead of “Busy” triggering the error message “The instance is deleted immediately after an operation.”.

The fix commit first checks if the instance is “Available” (in particular, not “Busy”) before settings its state to be “Deleted”:

            let mut instance = instances[instance_id].lock().await;
            match &instance.state {
                InstanceState::Available(_) => {
                    let _ = std::mem::replace(&mut instance.state, InstanceState::Deleted);
                    break;
                }
                InstanceState::Deleted => {
                    break;
                }
                InstanceState::Busy { .. } => {}
            }
1 Like